Reputation: 5992
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?
Upvotes: 55
Views: 30055
Reputation: 2092
The AVPlayer actually has a similar property as the playing property of AVAudioPlayer.
Take a look at the rate
property.
Upvotes: 9
Reputation: 38667
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:
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 seekingAVURLAssetPreferPreciseDurationAndTimingKey
when initializing AVURLAssets. And rely on values given by observer block.AVPlayer
to play multiple filesAVAudioPlayer
to play multiple filesUpvotes: 41
Reputation: 833
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.
Upvotes: 46