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?
An object that plays audio data from a file or buffer.
Overview. A player is a controller object that manages the playback and timing of a media asset. Use an instance of AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming.
And to track playing you can: "track changes in the position of the playhead in an AVPlayer object" by using addPeriodicTimeObserverForInterval:queue:usingBlock: or addBoundaryTimeObserverForTimes:queue:usingBlock:. You could throw in a Boolean flag to check the play status.
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.
identical support since iOS6
identical support:
AVAudioPlayer
directly.AVPlayer
with an AVAudioMix
on the AVPlayerItem
both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:
stop()
the AVAudioPlayer
before seeking AVURLAssetPreferPreciseDurationAndTimingKey
when initializing AVURLAssets. And rely on values given by observer block.AVPlayer
to play multiple filesAVAudioPlayer
to play multiple filesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With