我正在尝试通过直播使用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];
我如何直播视频?
答案 0 :(得分: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];
答案 1 :(得分: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);
}
}