AVPlayer vs. AVAudioPlayer

前端 未结 3 936
死守一世寂寞
死守一世寂寞 2020-12-23 12:39

The documentation for AVPlayer states the following:

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

However,

相关标签:
3条回答
  • 2020-12-23 13:09

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

    0 讨论(0)
  • 2020-12-23 13:11
    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.

    0 讨论(0)
  • 2020-12-23 13:13

    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:

    • You can set the mix volume of AVAudioPlayer directly.
    • You can set the mix volume of AVPlayer with an AVAudioMix on the AVPlayerItem

    3. seeking control

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

    • for AVAudioPlayer, it is suggested to stop() the AVAudioPlayer before seeking
    • for AVPlayer, it is suggested to pass the option AVURLAssetPreferPreciseDurationAndTimingKey when initializing AVURLAssets. And rely on values given by observer block.

    4. changing source

    • you need only one AVPlayer to play multiple files
    • you need multiple AVAudioPlayer to play multiple files
    0 讨论(0)
提交回复
热议问题