Anyone else having issues with MPMoviePlayerController in iPhone OS 3.0?

  • Twitter
  • Facebook
  • Digg
  • Reddit
  • StumbleUpon
  • del.icio.us
  • Google Bookmarks
July 21st, 2009 Posted by: (ELC) - posted under:Articles

Ok, so I’m currently updating an application for work and am getting some strange behavior with MPMoviePlayerController when trying to stream video.  The problem is:

When the user presses the “Done” button on the player during the buffering stage (right after it finishes saying “loading video…” but before the video starts playing), the player hides and the audio (for the video) begins to play in the background.  At this point, there are 3 ways for it to stop.

  1. Start playing another video
  2. Press the home button and exit the app
  3. Wait for the video to finish playing

Here is my code for playing the video.

-(void)playMovieAtURL:(NSURL*)theURL
{
	MPMoviePlayerController* theMovie = [[MPMoviePlayerController alloc]
	initWithContentURL:theURL];
 
	theMovie.scalingMode = MPMovieScalingModeNone;
	theMovie.movieControlMode = MPMovieControlModeDefault;
 
	[[NSNotificationCenter defaultCenter] addObserver:self
		selector:@selector(myMovieFinishedCallback:)
		name:MPMoviePlayerPlaybackDidFinishNotification
		object:theMovie];
 
	[theMovie play];
}
 
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
 
	MPMoviePlayerController* theMovie = [aNotification object];
	[[NSNotificationCenter defaultCenter] removeObserver:self
		name:MPMoviePlayerPlaybackDidFinishNotification
		object:theMovie];
 
	[theMovie release];
}

Is this a 3.0 issue or am I doing something dumb? I have sent a support ticket to Apple and will post a solution if I find one. Please let me know in the comments if you are having the same issue and how you solved it (if you did).
Happy iCoding!

  • http://www.elmadigital.com Murat

    Actually,
    i use a different way when streaming video with MPMoviePlayerController.

    Firstly, i hide the progress bar of video player than attach a cancel video button to MPMoviePlayerController window.

    When the button clicked, i sent to movieplyer stop message then both video and audio stops :)

    i hope, it works for you.

    -Murat

  • http://brandontreb.com Brandon

    @Murat,

    Sounds interesting. Have you tested this solution in 3.0?

  • http://www.puppetkaos.com Kelvin Kao

    I’ve seen this issue, but I am not sure if it happened for just 3.0 or earlier versions. What I did was explicitly say [theMovie stop] before I call [theMovie release]. This seems to solve the problem.

    Another problem I ran into was that in OS 2.2, if I created a MPMoviePlayerController with an url like this: “invalid_url”, it will just say the video is not found. However, in 3.0, it will crash (console shows an exception thrown). Changing that to “http://invalid_url” solves the problem.

  • Chris

    I have noticed the same problem with an App I had that was released back with 2.2 that worked fine. The issue only presents itself when run on iPhones that have 3.0.

  • Mike

    Hi, when you have a solution would you mind posting the code. We stream video (using windows) at work and would love to have an app for the iPhone to view this. Or do you know of any great examples out there?

    mike

  • http://clickedapps.com Brian

    I have the same problem. Its really ticking me off…

  • Charles

    If anyone knows how to get the current timeline out of the control that would be greatly appreciated. I can call setInitialPlayback and that works to start the video at a specific time (within the movie) however Apple provides no mechanism for getting the current position or time within a movie. Undocumented (double) currentTime returns garbage (although (void) setCurrentTime(double) works fine) I think I am going to have to get a hold of the slider and get its value. Anyone know how to do that????

  • http://brandontreb.com Brandon

    So, I wrote Apple and it turns out this is a bug in 3.0. They had me submit a bug report. Hopefully it get fixed in the near future.

  • Mopy

    Has anyone tried to use the MoviePlayer to play a .m3u8 playlist followed by a mp4 file stored in the file system. In my case, the playlist plays fine, but a subsequent attempt to play the local mp4 file fails. If I don’t play the playlist, then the local file seems to play just fine.

    Anyone know how to fix this issue?

  • Mathijs

    We’ve also spend a lot of time trying to find a solution or workaround for this problem.

    So you did get a reply from Apple acknowledging that it’s a 3.0 bug? And what seems to be the best workaround for this MPMoviePlayer ‘buffering/done’ at this moment?

  • jay

    Add the following line of the code in the didFinishNotification:

    celebVideo.initialPlaybackTime = -1.0;

    only works on OS 3.0.

    // get current MPMoviePlayerController object from (NSNotification*)aNotification

    MPMoviePlayerController *celebVideo = [aNotification object];

    //manually stop movie
    [celebVideo stop];

    // set initialPlaybackTime property of the MPMoviePlayerController class to -1.0 to prevent continued playback in case user closes
    // movie player before pre loading has finished.

    celebVideo.initialPlaybackTime = -1.0;

    [[NSNotificationCenter defaultCenter] removeObserver:self
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:celebVideo];

    [celebVideo release];

  • Justin

    Thanks Jay!

    I was having this same problem. setting initialPlaybackTime = -1.0 solved the issue of the video playing after the user pressed Done, when the video was still buffering.

  • Emadrazo

    ThankYouSoMuch!!!

    I have been looking for this day and night :) it works!!! thank you

    PD.- I am testing in 3.0

  • Andrew

    Thank you VERY MUCH! I’ve spend some hours trying to solve it! initialPlaybackTime = -1.0 works great!

  • http://brandontreb.com Brandon

    @Jay

    You win! thanks for pointing that out man. Ill be sure to check it out!

  • Ross

    Thanks a lot, man, you rock!

  • xuzepei

    Yes, I have the same problem as you.

  • xuzepei

    RT @Andrew Says:
    Thank you VERY MUCH! I’ve spend some hours trying to solve it! initialPlaybackTime = -1.0 works great!

  • rlk

    [videoPlayer stop];
    videoPlayer.initialPlaybackTime = -1.0;

    in the didFinishCallback also remedies a problem I was having where repeated playback of the same video became choppy.

  • William

    “movie.initialPlaybackTime = -1.0;” seems to be introducing a memory leak… take a look at it under Instruments to see what I mean…

  • volverein

    Thanks jay :-)

  • Raja

    How to stream .asx and .pls file?…. I am indeed of this…

  • Fleur

    Hi everyone! I need some help. I used the code to stream a video and when i run my app it appears to be downloading but a sec later it quits dowloading.
    Does anyone know why is this happening?
    Thanks!

  • lobato

    I solved this by calling [theMovie autorelease], instead of release.

  • Vinuthna

    Which is the player internally fro streaming an audio file by MPMoviePlayerController in iPhone?

  • Yunjuan Li

    I have same issue here, let me know if you find the solution. Thanks

  • Sohambhowmik

    Refer to http://stackoverflow.com/questions/5637956/mpmovieplayercontroller-plays-after-canceling-in-3-1-2

blog comments powered by Disqus