AVPlayer 与 AVAudioPlayer

发布于 2024-09-10 15:36:09 字数 608 浏览 4 评论 0原文

AVPlayer 文档声明如下:

[该]播放器同样适用于本地和远程媒体文件

但是,AVAudioPlayer 文档陈述如下:

Apple 建议您使用此类进行音频播放,除非您正在播放从网络流捕获的音频

对于我正在做的工作,我需要 AVAudioPlayer 的一些功能,但我的所有音频都是流式传输的。我需要从 AVAudioPlayer 获得 AVPlayer 没有的主要功能是“播放”属性。如果没有该属性等,就很难构建播放器 UI。

那么 AVPlayer 和 AVAudioPlayer 之间有什么区别使得后者不适合网络流媒体呢?有没有办法从 AVAudioPlayer 提供的 AVPlayer 获取一些信息,例如“播放”属性?

The documentation for AVPlayer states the following:

[The] player works equally well with local and remote media files

However, the documentation for AVAudioPlayer states the following:

Apple recommends that you use this class for audio playback unless you are playing audio captured from a network stream

For the work I am doing I need some of the capabilities of AVAudioPlayer, but all my audio is being streamed. The main thing I need from AVAudioPlayer that AVPlayer does not have is the "playing" property. It is difficult to build a player UI without that property, among others.

So what is the difference between AVPlayer and AVAudioPlayer that makes the latter unsuitable for network streaming? Is there a way to get some of the info from AVPlayer that AVAudioPlayer provides such as the "playing" property?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感悟人生的甜 2024-09-17 15:36:10
  1. AVPlayer 可以使用带有 iPod 库 URL 的 AVURLAsset 从 AVPlayerItem 进行播放。 AVAudioPlayer 无法从 iPod 库 url 播放。

  2. AVPlayer没有音量属性,需要使用系统音量设置,只能通过硬件开关或MPVolumeView来控制。但是你可以设置AVAudioPlayer的混音音量。

  3. AVPlayer 在查找后似乎报告了不正确的 currentTime。但 AVAudioPlayer 报告准确。

  1. AVPlayer can play from AVPlayerItem using AVURLAsset with an iPod library url. The AVAudioPlayer cannot play from an iPod library url.

  2. AVPlayer has no volume property and requires the use of the system volume setting which can be controlled only by the hardware switch or an MPVolumeView. But you can set the mix volume of AVAudioPlayer.

  3. AVPlayer seems to report an incorrect currentTime after seeking. But AVAudioPlayer reports accurately.

征﹌骨岁月お 2024-09-17 15:36:10

7 年后...

从依赖 Swift 和 CocoaPods 的角度来看,所以我的答案是仅针对 iOS 8+ 进行比较。

1. iPod 库支持

iOS6以后一致支持

2.音量控制

一致支持:

3. 寻求控制

AVPlayer 和 AVAudioPlayer 似乎在寻求后报告不正确的 currentTime:

4. 更改来源

  • 您只需要一个 AVPlayer 即可播放多个文件
  • 您需要多个 AVAudioPlayer 即可播放多个文件

7 years after...

From a point of view with dependence on Swift and CocoaPods, so my answer is comparing for iOS 8+ only.

1. iPod library support

identical support since iOS6

2. volume control

identical support:

3. seeking control

both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:

4. changing source

  • you need only one AVPlayer to play multiple files
  • you need multiple AVAudioPlayer to play multiple files
找个人就嫁了吧 2024-09-17 15:36:10

AVPlayer 实际上具有与 AVAudioPlayer 的播放属性类似的属性。
查看 rate 属性。

The AVPlayer actually has a similar property as the playing property of AVAudioPlayer.
Take a look at the rate property.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文