在iPhone中播放流媒体视频

在iPhone中播放流媒体视频,iphone,ios,objective-c,xcode,mpmoviewcontroller,Iphone,Ios,Objective C,Xcode,Mpmoviewcontroller,我正在尝试使用MPMoviewPlayerController在我的应用程序中通过实时流媒体播放视频它对保存在我的捆绑包中的视频工作正常,但对实时流媒体不工作我正在使用此 //for Bundle Video NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"Video.mp4" ofType:nil]; //for Streaming Video NSURL *videoURL = [NSURL URL

我正在尝试使用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];

如何流式传输实时视频?

请使用以下代码从捆绑包中获取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];

我不知道确切的原因,但MPMoviePlayerController需要声明为强属性。如果不强声明其属性,则只会显示黑色视图

因此,为MPMoviePlayerController声明一个强属性

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;


您发布的URL指向位于Web服务器上的文件,而不是流
mpmovieplayervewcontroller
将接受流媒体,但不只是服务器上的文件。请提供一些流媒体链接,我尝试了一些,但没有工作。检查此项我想使用MPMoviePlayer播放视频,不在Webview中如果视频在捆绑包中,但无法工作,但我想从一些服务器(如我自己的服务器)流媒体观看并在几秒钟后播放电影回放完成called@MuzamilHassan我不知道确切的原因,但MPMoviePlayerController需要声明为强属性。如果不强声明其属性,则只会显示黑色视图。请看一下我的最新答案。
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);
     }
 }