Search code examples
iphoneobjective-ciosios4mpmovieplayercontroller

MPMoviePlayerViewController not palying in ipod and iPhone


-(void)playVideo:(NSURL *)url{

    if (videoPlayer) {
        [videoPlayer release];
        videoPlayer = nil;
    }
    videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    url = nil;
    videoPlayer.moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
    videoPlayer.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    videoPlayer.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
    videoPlayer.view.backgroundColor = [UIColor blackColor]; 


    [[UIApplication sharedApplication]
     setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];


    [videoPlayer.moviePlayer prepareToPlay];
    videoPlayer.moviePlayer.shouldAutoplay = YES;
    videoPlayer.hidesBottomBarWhenPushed = YES;
    self.navigationController.navigationBarHidden=NO;
    videoPlayer.navigationItem.hidesBackButton = YES;
    [self.navigationController pushViewController:videoPlayer animated:YES];

    [self addObservers];
}

Can anyone say what is wrong with this code? The url is streaming http link. Video player is appearing but after a while it disappears. It is working in 3G network but not in wifi


Solution

  • As you are saying that it was working on 3G but not on WiFi Network, your issue is most likely not related to the code but to the movie-file/s you are testing.

    Make sure the m3u8-snippet is complete and valid also for low bandwidth. Test the m3u8 with Apples Mediastream Validator as described by this Best Practice Guide and this Article.