AVPlayer 与 AVAudioPlayer
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
AVPlayer 可以使用带有 iPod 库 URL 的 AVURLAsset 从 AVPlayerItem 进行播放。 AVAudioPlayer 无法从 iPod 库 url 播放。
AVPlayer没有音量属性,需要使用系统音量设置,只能通过硬件开关或MPVolumeView来控制。但是你可以设置AVAudioPlayer的混音音量。
AVPlayer 在查找后似乎报告了不正确的 currentTime。但 AVAudioPlayer 报告准确。
AVPlayer can play from AVPlayerItem using AVURLAsset with an iPod library url. The AVAudioPlayer cannot play from an iPod library url.
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.
AVPlayer seems to report an incorrect currentTime after seeking. But AVAudioPlayer reports accurately.
7 年后...
从依赖 Swift 和 CocoaPods 的角度来看,所以我的答案是仅针对 iOS 8+ 进行比较。
1. iPod 库支持
iOS6以后一致支持
2.音量控制
一致支持:
AVAudioPlayer
的混音音量。上的
AVAudioMix
设置AVPlayer
的混音音量AVPlayerItem3. 寻求控制
AVPlayer 和 AVAudioPlayer 似乎在寻求后报告不正确的 currentTime:
stop()
AVAudioPlayer
,建议传递选项AVURLAssetPreferPreciseDurationAndTimingKey
初始化 AVURLAssets 时。 并依赖观察者块给出的值。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:
AVAudioPlayer
directly.AVPlayer
with anAVAudioMix
on theAVPlayerItem
3. seeking control
both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:
stop()
theAVAudioPlayer
before seekingAVURLAssetPreferPreciseDurationAndTimingKey
when initializing AVURLAssets. And rely on values given by observer block.4. changing source
AVPlayer
to play multiple filesAVAudioPlayer
to play multiple filesAVPlayer 实际上具有与 AVAudioPlayer 的播放属性类似的属性。
查看
rate
属性。The AVPlayer actually has a similar property as the playing property of AVAudioPlayer.
Take a look at the
rate
property.