AVPlayer vs. AVAudioPlayer

IphoneAudioStreamingIos4Core Audio

Iphone Problem Overview


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?

Iphone Solutions


Solution 1 - Iphone

  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.

Solution 2 - Iphone

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

Solution 3 - Iphone

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjoshwbrickView Question on Stackoverflow
Solution 1 - IphoneCJ HansonView Answer on Stackoverflow
Solution 2 - IphoneCœurView Answer on Stackoverflow
Solution 3 - IphonetadejsvView Answer on Stackoverflow