编写应用程序将视频流传输到iPhone
我感兴趣的是创建一个iPhone应用程序,它可以从一个中央服务器上传视频,YouTube风格。我想知道以前是否有人尝试过这样做,现有的API抵抗力最低的途径是什么?我真的不知道这通常是怎么做的。我会使用插座吗?只是在这里找方向。谢谢 QuickTime视频已经流到手机上。阻力最小的方法是使用媒体播放器控制器,并将其指向流服务器上的流媒体文件。如果流服务器已启动并准备就绪,则很容易实现youtube风格的视频控制器编写应用程序将视频流传输到iPhone,iphone,objective-c,video,video-streaming,Iphone,Objective C,Video,Video Streaming,我感兴趣的是创建一个iPhone应用程序,它可以从一个中央服务器上传视频,YouTube风格。我想知道以前是否有人尝试过这样做,现有的API抵抗力最低的途径是什么?我真的不知道这通常是怎么做的。我会使用插座吗?只是在这里找方向。谢谢 QuickTime视频已经流到手机上。阻力最小的方法是使用媒体播放器控制器,并将其指向流服务器上的流媒体文件。如果流服务器已启动并准备就绪,则很容易实现youtube风格的视频控制器 NSString *videoURLString = @"http://path-
NSString *videoURLString = @"http://path-to-iphone-compliant-video-stream";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[self.view addSubview:moviePlayer.view];
您需要处理显示视频播放器视图的控制器(在本例中为self
)
在iOS 3.2+MPMoviePlayerViewController中,它更容易:
NSString *videoURLString = @"http://path-to-iphone-compliant-video-stream";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentmovieplayervicewcontrolleranimated
是MediaPlayer对iOS 3.2+中的FWViewController
的附加方法,它负责创建视图控制器并将其推到堆栈上,使用从底部滑动的动画设置动画,正如在youtube.app中一样。苹果有一篇关于设置媒体流服务器端的详细文章:
和最佳做法说明:
它不仅包含有关流式服务体系结构和用于构建流式服务的工具的信息,而且还包含必须满足的此类服务的一些要求以及对实时测试流的引用。使用此代码可以使用低内存。关于流媒体视频
-(IBAction)playMovie:(NSURL *) theURL
{
NSURL *fileURL = theURL;
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
虽然现有的答案很好,但如果您需要使用非HTTP流(例如mms或rtmp)或非Apple支持的音频/视频编解码器,事情会变得更复杂
我自己不是专家,但我一直在使用它来解决这些问题,它使定制客户机变得更容易(后台流、暂停流等)。如果您也有这些要求,可能值得一看。2018答案您可以使用
avplayervewcontroller
,因为自从iOS 9以来,MPMoviePlayerController
已被弃用
NSURL *url = [NSURL URLWithString:videoUrl];
_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:url];
_playerViewController.player.volume = 1;
_playerViewController.showsPlaybackControls = YES;
_playerViewController.view.frame = CGRectMake(....);
[self.view addSubview:_playerViewController.view];