我在我的mac上设置了一个darwin流媒体服务器。现在我需要在我的iphone上实时播放这些视频
但问题是,甚至在视频播放之前就调用了MPMoviePlayerPlaybackDidFinishNotification
我已经检查了服务器,它的启动和运行,我也成功地在safari和quicktime中打开了网址。但是视频不会在模拟器上播放,我写的代码是
NSURL *movieURL=[NSURL fileURLWithPath:@"rtsp://10.41.37.160/sample_300kbit.mov"];
// NSURL *movieURL = [NSURL URLWithString:@"rtsp://10.41.37.160/sample_300kbit.mp4"];
if (movieURL != nil)
{
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[moviePlayer.view setFrame: CGRectMake(0, 0, 320, 400)];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen=YES;
// moviePlayer.initialPlaybackTime = -1.0;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerScalingModeDidChangeNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay=YES;
[moviePlayer play];
//[self reloadInputViews];
}
-(void)moviePlayBackDidFinish: (NSNotification*)notification
{
self.navigationItem.hidesBackButton = FALSE;
moviePlayer = [notification object];
[moviePlayer play];
}
-(void)endPlay: (NSNotification*)notification
{
NSLog(@"end Playing");
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerScalingModeDidChangeNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer stop];
[moviePlayer release];
}发布于 2011-10-25 07:07:52
我找不到任何文档来支持这一点,但是你不能在iOS上播放RTSP stream。
您必须使用HTTP (直接指向电影文件,或使用HTTP实况流)。我不认为Darwin Streaming server可以做HLS,但你可以使用普通的web服务器提供直接的电影文件。
请注意,视频可以使用的编解码器是somewhat limited...
https://stackoverflow.com/questions/7873700
复制相似问题