1

I am having a video file on server. When I copy the URL and run in safari it start playing video in browser using quick time player, but it is not playing in simulator, it is showing loading but nothing happening. Please help me. How can I solve this?

Thanks.

-

(void)playMovieWithUrl:(NSString*)url{
    moviePlayerViewController = [[MPMoviePlayerViewController alloc] init];
    moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleDefault;

    moviePlayerViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [self.view addSubview:moviePlayerViewController.moviePlayer.view];
   [moviePlayerViewController.moviePlayer setFullscreen:YES];

   [moviePlayerViewController.moviePlayer stop];
    NSLog(@"playerUrl %@",url);
    [moviePlayerViewController.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming];
    [moviePlayerViewController.moviePlayer setContentURL:[NSURL URLWithString:url]];
    [moviePlayerViewController.moviePlayer prepareToPlay];
    //moviePlayerViewController.moviePlayer.initialPlaybackTime = interval;
    [moviePlayerViewController.moviePlayer play];

}
  • extension of video file ? – Rushabh Dec 24 '13 at 11:23
  • the video file is of mp4 type – user1841079 Dec 24 '13 at 11:25
  • Remove [moviePlayerViewController.moviePlayer stop]; and add observer [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object: moviePlayerViewController]; and in "moviePlayBackDidFinish" method release controller and remove observer like [moviePlayerViewController autorelease]; moviePlayerViewController = nil; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; – shraddha hattimare Dec 24 '13 at 11:26
  • https://discussions.apple.com/thread/5361136 – Rushabh Dec 24 '13 at 11:27
  • you can use UIWebView also –  Dec 24 '13 at 11:28
  • @ shraddha hattimare I tried this but still facing same issue – user1841079 Dec 24 '13 at 11:33
  • @rmrahul this is not proper solution.There is another way that you can download the video and then play but i don't want to download i want to play it from server. – user1841079 Dec 24 '13 at 11:37
  • is it live streaming? – Charan Giri Dec 24 '13 at 12:21
  • possible duplicate of [Why won't my MPMoviePlayerController play?](http://stackoverflow.com/questions/15058138/why-wont-my-mpmovieplayercontroller-play) – Till Dec 25 '13 at 02:39
  • Do not use `MPMoviePlayerViewController` within a custom view-stack. For a proper solution on your issue, see the given duplicate's answer. – Till Dec 25 '13 at 02:48

1 Answers1

0

This works for me:

NSURL *streamURL = [NSURL URLWithString:@"http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"];
_streamPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:streamURL];
[_streamPlayer.view setFrame:self.view.bounds];
[self.view addSubview:_streamPlayer.view];
[_streamPlayer.moviePlayer play];

_streamPlayer is declared as:

@property (strong, nonatomic) MPMoviePlayerViewController *streamPlayer;

Note that I am adding the MPMoviePlayerViewController's view while you are adding its moviePlayer.view.

3111767
  • 26
  • 3
  • 1
    The reasoning for the OP's code to fail is the use of ARC (as shown in the duplicate) which releases the player immediately. I would strongly discourage to use `MPMoviePlayerViewController` within a custom view-stack but use `MPMoviePlayerController` only. `MPMoviePlayerViewController` is meant for fullscreen playback only! – Till Dec 25 '13 at 02:44