ios4streamingmpmovieplayercontroller

Trouble in playing video from URL in iPhone using MPMoviePlayerController


I am trying to play a video through a link in my app. The code goes here

NSURL *videoURL = [NSURL URLWithString:viewURL];

NSLog(@"Filepath is: %@", viewURL);

MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(playbackFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:movie];

movie.view.frame = CGRectMake(0.0f, 50.0f, 320.0f, 320.0f);
movie.fullscreen = YES;
[self.view addSubview:movie.view];

[movie play];

This was written in a method that is called on a button press. This code once worked but now there is no response from the code. Nothing happens when I click on the button even when I connected everything properly in my xib file.


Solution

  • Try this:

    Remove

    [movie play];

    and add

    movie.shouldAutoplay = YES;
    [movie prepareToPlay]; 
    

    instead.

    Streaming movies (m3u8), from my experience, are a bit quirky when it comes to starting the playback. In certain situations, your original version won't work properly but my replacement always works.

    EDIT: You may also want to check your encodings and delivery using Apples Mediastream Validator as described by this Best Practice Guide and this TechNote.