MPMoviePlayer play on when application goes Background when incoming call is coming - iphone

I am developing an audio streamer and have declared an interruption listener,
that means when an interruption occurs - like an incoming call or an sms.After complete my call again automatically play that audio live stream
Explain
my first question Is it possible.... (that means if my song is ten min . After 2 min playing, suddenly incoming call is coming at that time i am talking 4 min... So my song should be continue from 6th min(that means 4 min should be background running without noise ) )
I am MPMoviePlayer in IOS5
player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
[player prepareToPlay];

My guess is you can do it by:
Capture the current time when you app got interrupted.
When applicationDidBecomeActive got called. Calculate the elapsed time base on the time captured above.
Initialize the MPMoviePlayerController with initialPlaybackTime to seek to the calculated offset.

Related

count the number of loops and stop playing the audio

I have a small 4 second video file which will be played again and again.For that I have used
[player setRepeatMode:MPMovieRepeatModeOne];
but after the 1st loop I want the audio to be stopped and only video should be played.I tried setting [player setUseApplicationAudioSession:NO];
but its not working.
Any help?
There is no direct way to mute or adjust volume of MPMoviePlayerController. All you need to do is to control your device's volume.
Get MPMoviePlayerPlaybackDidFinishNotification and write Following code in specific check
[[MPMusicPlayerController applicationMusicPlayer] setVolume:0];
I don't think there is a ready to use option to count loops.
I would recommend to extend player and make your own method to play sound X times.
For that you can play this sound without repeat mode X times in a row. To detect that sound has finished playback check for MPMusicPlayerControllerPlaybackStateDidChangeNotification and beginGeneratingPlaybackNotifications. Based on that you play it again and again and decrease a count for how much times you want to play it.

Difference between prepareToPlay and Play in MPMoviePlayerController

Please let me know the difference between prepareToPlay & play Methods in MPMoviePlayerController at the time of Video Play.
The syntax are:
[moviePlayer prepareToPlay];
And
[moviePlayer play];
As Method say that
prepareToPlay - is not starting to play but it is under process for play whatever (video/audio).
play - says that it is do string to play whatever (video/audio).
as Document say:
play
Initiates playback of the current item. (required)
- (void)play
Discussion
If playback was previously paused, this method resumes playback where it left off; otherwise, this method plays the
first available item, from the beginning.
If a movie player is not prepared for playback when you call this
method, this method first prepares the movie player and then starts
playback. To minimize playback delay, call the prepareToPlay method
before you call this method.
To be notified when a movie player is ready to play, register for the
MPMoviePlayerLoadStateDidChangeNotification notification. You can then
check load state by accessing the movie player’s loadState property.
Availability Available in iOS 3.2 and later. Declared In
MPMediaPlayback.h
prepareToPlay
Prepares a movie player for playback. (required)
- (void)prepareToPlay
Discussion
If a movie player is not already prepared to play when you
call the play method, that method automatically calls this method.
However, to minimize playback delay, call this method before you call
play.
Calling this method may interrupt the movie player’s audio session.
For information on interruptions and how to resond to them, see Audio
Session Programming Guide.
Availability Available in iOS 3.2 and later.
Declared In MPMediaPlayback.h
For More Information read This Official Documentation.
To minimise playback latency by performing expensive operations upfront.
In order to play back a multimedia file, such as a QuickTime movie, there is a non-trivial amount of loading and processing required before the file can actually be played. Having separate play and prepareToPlay methods allows the developer to choose when potentially expensive operations involved with playback can be performed, to minimise the delay when the user actually presses the play button.
For example, the header needs to be read and parsed, and metadata extracted. The chapter index might need to be read, and the player might need to seek to the end of the file to read chunk offset tables, read thumbnails, poster frames and and many more. Also, to enable rapid playback when the user presses play, the system probably wants to load, uncompress and cache the first second or so of audio and video content. All of this can take a noticeable amount of time, and would be performed by the prepareToPlayback method.
Given the above, the play method can immediately start to play the multimedia content when the user nominates. Obviously, if the media hasn't already been prepared, the system would call prepareForPlayback for you at the start of play to perform these necessary preparations.
In your app, for example, the user might select a multimedia clip in one step. You could call prepareToPlay right away, and show the poster frame in the preview window. Then when the user presses the Play> button, the content is ready to go.
A simplistic parallel in the analog world might be something akin to threading the tape into a spool, winding up the spool and pretensioning the tape, positioning the tape head at the start of the content. Then when you press Play, the sound is heard almost immediately.
prepareToPlay
Prepares a movie player for playback. (required) If a movie player is
not already prepared to play when you call the play method, that
method automatically calls this method. However, to minimize playback
delay, call this method before you call play.
play
Initiates playback of the current item. (required) If playback was
previously paused, this method resumes playback where it left off;
otherwise, this method plays the first available item, from the
beginning. If a movie player is not prepared for playback when you
call this method, this method first prepares the movie player and then
starts playback. To minimize playback delay, call the prepareToPlay
method before you call this method.
Please visit MPMediaPlayback Protocol Reference

For how long does the AVPlayer continues to buffer from an URL after a pause?

I was reading the AVPlayer class documentation and I couldn't find the answer for my question.
I'm playing a streamed audio from the Internet on my iPhone app and I'd like to know if after a [myAVPlayer pause]; invocation myAVPlayer will keep downloading the audio file on the background for a long time.
If the user pushes the "Pause" button, invoking [myAVPlayer pause]; and then leaves the app, will myAVPlayer keep downloading a large amount of data?
I'm concerned about this when the user is on 3G Network.
I am faced with the same question and have done some experimentation. My observations are only valid for video, but if they are also valid for audio, then AVPlayer will try to buffer around 30s of content when you press pause. If you have access to the webserver, you could run tcpdump/wireshark and see how long after you press pause that the server continues to send data.
You can manage how long AVPlayer continues to buffer.
You need to manage preferredForwardBufferDuration of avplayer currentItem. If you want to stop buffering set value to 1 because if you set it to 0 it will be set up automatically
self.avPlayer.currentItem.preferredForwardBufferDuration = 1;
From Apple documentation: This property defines the preferred forward buffer duration in seconds. If set to 0, the player will choose an appropriate level of buffering for most use cases. Setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources.

iphone, my AVPlayer player is playing video really fast

My application is using AVPlayer to play video. There is a serious problem that my app currently experience. Sometimes, it is playing the video very fast although I checked to make sure that I either set the self.player.rate = 0.3 or self.player.rate = 1 or not set the rate at all. This only happens sometimes and it happens to all the videos I have.
Can anyone give me any hint on the current problem?
I finally know the answer. I called [player setRate:0.3] and [player play] at the same time and the second call override the first call, which sets the rate to be 0 (normal). The method setRate: already set the rate for the player and play the video already

How to reset MPMoviePlayerController timeline to zero at movie end

Streaming 10 seconds movie from server, but timeline stops at 8 seconds.
There are no errors, so I would like to reset MPMoviePlayerController timeline left side as 00:10 and right side as 00:00 to make it look like the whole movie was played. How could I do that?
Try the following - assuming that you have an instance of the MPMoviePlayerController called mp;
[mp setCurrentPlaybackTime:mp.endPlaybackTime];
Haven't found any other video with same symphtons, so let's call this a bug in video data or its conversion. Case closed.