AVPlayer vs. 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 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 anAVAudioMix
on theAVPlayerItem
3. seeking control
both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:
- for AVAudioPlayer, it is suggested to
stop()
theAVAudioPlayer
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
The AVPlayer actually has a similar property as the playing property of AVAudioPlayer.
Take a look at the rate
property.