0

我正在尝试通过使用 MPMoviewPlayerController 实时流式传输在我的应用程序中播放视频,它对于保存在我的捆绑包中的那些视频工作正常,但它不适用于实时流式传输我正在使用这个

 //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];

我如何流式传输实时视频?

4

2 回答 2

0

请使用以下代码从包中获取 Mp4 文件

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

愿这有助于解决您的问题

已编辑

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];
于 2013-04-03T13:08:04.497 回答
0

我不知道确切的原因,但MPMoviePlayerController需要声明为一个强属性。如果你没有强烈声明它的属性,那么只会出现黑色视图。

所以为 MPMoviePlayerController 声明一个强属性

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

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];

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    NSError *error = [[notification userInfo] objectForKey:@"error"];
    if (error) {
       NSLog(@"Did finish with error: %@", error);
     }
 }
于 2015-06-16T11:33:44.057 回答