0

i am trying to play video in my app by live streaming using MPMoviewPlayerController its work fine for those videos which are saved in my bundle but its not working for live streaming i am using this

 //for Bundle Video
     NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Video.mp4" ofType:nil];

//for Streaming Video
    NSURL *videoURL = [NSURL URLWithString:@"http://streaming.disponivel.uol.com.br/video360p2/288148-1192657.mp4"];

    self.playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
    [self.view addSubview:self.playerController.view];
    self.playerController.view.frame = CGRectMake(0, 0, 320, 400);
    [self.playerController.moviePlayer play];

How I stream live video?

Thanakron Tandavas
  • 5,615
  • 5
  • 28
  • 41
Muzamil Hassan
  • 841
  • 1
  • 11
  • 23

2 Answers2

0

Please Use Following code for the fetch the Mp4 File From the bundle

 NSString *url = [[NSBundle mainBundle] pathForResource:@"Video" ofType:@"mp4"];
   MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];

May this Help to solve your problem

Edited

NSURL *url = [NSURL URLWithString:@"http://streaming.disponivel.uol.com.br/video360p2/288148-1192657.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame;
if(self.interfaceOrientation ==UIInterfaceOrientationPortrait)
    frame = CGRectMake(20, 69, 280, 170);
else if(self.interfaceOrientation ==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation ==UIInterfaceOrientationLandscapeRight)
    frame = CGRectMake(20, 61, 210, 170);
[moviePlayer.view setFrame:frame];  // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];

[moviePlayer prepareToPlay];
[moviePlayer play];
Sumit Mundra
  • 3,891
  • 16
  • 29
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
  • if the video is in bundle than it work but i want to stream from some server like my own – Muzamil Hassan Apr 03 '13 at 13:11
  • not working black view and after few seconds moviePlayBackDidFinish called – Muzamil Hassan Apr 03 '13 at 13:26
  • @MuzamilHassan I don't know the exact reason but the **MPMoviePlayerController** needs to be a strong property declared. If you not declare its property strongly then only black view will appear. Please have a look on my updated answer. – Mayank Jain Jun 16 '15 at 11:33
0

I don't know the exact reason but the MPMoviePlayerController needs to be a strong property declared. If you not declare its property strongly then only black view will appear.

So declare a strong property for MPMoviePlayerController

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

and

NSURL *url = [NSURL URLWithString:@"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.moviePlayer setControlStyle:MPMovieControlStyleDefault];
self.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame = CGRectMake(20, 80, 280, 280); //change according to your need

[self.moviePlayer.view setFrame:frame];  // player's frame must match parent's
[self.view addSubview: self.moviePlayer.view];
[self.view bringSubviewToFront:self.moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:self.moviePlayer];

[self.moviePlayer prepareToPlay];
[self.moviePlayer play];

and

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error) {
       NSLog(@"Did finish with error: %@", error);
     }
 }
Mayank Jain
  • 5,663
  • 7
  • 32
  • 65