AVPlayer vs. AVAudioPlayer

The documentation for AVPlayer reads as follows:

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

However, the documentation for AVAudioPlayer states the following:

Apple recommends using this class to play sound if you don’t play sound captured from the network stream.

For the work I'm doing, I need some AVAudioPlayer features, but all my audio is streamed. The main thing that I need from AVAudioPlayer, which AVPlayer does not have, is the play property. It is difficult to create a game interface without this property, among others.

So what is the difference between AVPlayer and AVAudioPlayer, which makes the latter unsuitable for network streaming? Is there a way to get some information from AVPlayer that AVAudioPlayer provides, for example, the play property?

+43
iphone ios4 audio streaming core-audio
Jul 19 '10 at 16:15
source share
3 answers
  • AVPlayer can be played from AVPlayerItem using AVURLAsset with the URL of the iPod library. AVAudioPlayer cannot play the URL of the iPod library.

  • AVPlayer does not have volume properties and requires the use of system volume settings, which can only be controlled by a hardware switch or MPVolumeView. But you can set the mixing volume of AVAudioPlayer.

  • AVPlayer seems to report an incorrect current time after the search. But AVAudioPlayer accurately reports.

+34
Nov 04 '10 at 14:20
source share

AVPlayer actually has a similar property as the AVAudioPlayer playback property. Take a look at the rate property.

+6
Jul 19 '10 at 17:30
source share

7 years after ...

In terms of dependency on Swift and CocoaPods, my answer is only compared for iOS 8+.

1. Support iPod library

identical support with iOS6

2. volume control

identical support:

  • You can directly set the mixing volume of AVAudioPlayer .
  • You can set AVPlayer mixing volume using AVAudioMix on AVPlayerItem

3. search for control

both AVPlayer and AVAudioPlayer seem to report an incorrect current time after a search:

  • for AVAudioPlayer, stop() AVAudioPlayer before searching
  • for AVPlayer, it is recommended to pass the AVURLAssetPreferPreciseDurationAndTimingKey option when initializing AVURLAssets. And rely on the values ​​given by the observer unit .

4. change of source

  • you only need one AVPlayer to play multiple files.
  • you need multiple AVAudioPlayer to play multiple files.
+5
Mar 16 '17 at 8:52
source share



All Articles