MPMoviePlayerController - how to tell what bitrate is playing? - iphone

The HTTP Live Streaming format supports variable bitrates, which are described in the m3u8 file.
Is it possible to get the bitrate of the currently playing stream?

No, you can't get that information from MPMoviePlayerController
To get the information you want, you could use AVPlayer and AVPlayerItems, which will then create AVAsset items that you can interrogate to discover their properties.
Once you have a AVPlayer, you can find the current AVPlayerItem using currentItem. From that, you can get the asset property.
A AVAsset has AVAssetTracks and this has the formatDescriptions property. Somewhere in there you should find the bitrate.

Related

AVPlayer buffer

I use AVPlayer for video and I want to see how full is a buffer(in percent). Maybe are there some properties of player that I can use? I know just about "isPlaybackBufferFull" and "isPlaybackBufferEmpty", but I look for value.

Getting current MP3 filename with AVAudioPlayer

I've got AVAudioPlayer playing some MP3 in background. AVAudioPlayer is singleton instance shared across app. Is it possible to detect current filename of MP3 being played at a time? I can't see any method in delegate, there's duration, currentTime but nor filename or something like this.
Other thing I consider if this method fails is reading MP3 tags and get track name from it - is it possible with AVAudioPlayer?
Thanks in advance!
You can get filename of current playing media in AVAudioPlayer like this:
NSString *mediaFileName = [[youAVAudioPlayer.url absoluteString] lastPathComponent];
Note condition is that: Returns nil if the audio player was not initialized with a URL.
If you initialize the AVAudioPlayer with a url, you can read that property. AVAudioPlayer does not read the tags in the MP3 file, so it will not help with that.
You may find AVAsset interesting as a way to get metadata from an MP3. Quick Tutorial.

How to know when AVPlayer uses the audio only bit-rate?

While streaming when encountering slow connectivity the AVPlayer may choose to play the lowest bit-rate in the HTTP Live Streaming playlist.
Is there a way to identify this transition?
I've tried observing the AVPlayerItem "tracks" property via KVO to see when it contains only audio but in most cases the tracks property isn't changed even though the player switched to the audio only stream.
I found out that the AVPlayerItem tracks property was not dependable on the simulator but somewhat more dependable on the actual device (with a ~5 seconds deviation).
Whenever the tracks property changes (you can find out when via KVO) you should traverse the tracks and see if there are any tracks with 'mediaType' set to AVMediaTypeVideo.
If there are none then you can conclude that you are in an audio only state.

Movie is played with some delay after calling play on MPMoviePlayerController

I am developing an iPhone application in which I play videos using MPMoviePlayerController.
Sometimes, some of the videos don't play immediately after I call play on MPMoviePlayerController.
I have called prepareToPlay and in the notified method of MPMediaPlaybackIsPreparedToPlayDidChangeNotification, I am calling play on MPMoviePlayerController.
Could someone help in identifying the problem here?
Thanks,
Laxmilal
From my answer in a similar thread (reducing-the-initial-delay-when-playing-remote-video-content) - Note this fragment of the solution is valid for both, remote and local video content.
Use theMPMoviePlayerController.movieSourceTypeproperty when initializing your
player to cut down the media
recognition delay.
From the MPMoviePlayerController Class Reference:
The default value of this property is
MPMovieSourceTypeUnknown. This
property provides a clue to the
playback system as to how it should
download and buffer the movie content.
If you know the source type of the
movie, setting the value of this
property before playback begins can
improve the load times for the movie
content. If you do not set the source
type explicitly before playback, the
movie player controller must gather
this information, which might delay
playback.

AVPlayer vs. AVAudioPlayer

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?
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 an AVAudioMix on the AVPlayerItem
3. seeking control
both AVPlayer and AVAudioPlayer seem to report an incorrect currentTime after seeking:
for AVAudioPlayer, it is suggested to stop() the AVAudioPlayer 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.