编写一个应用程序将视频流式传输到 iPhone [英] Writing an app to stream video to iPhone
问题描述
我有兴趣创建一个 iPhone 应用程序,该应用程序可以从中央服务器流式传输视频,YouTube 风格.我想知道以前是否有人尝试过这样做,抵抗力最小的现有 API 等的路径是什么?我真的不知道这通常是如何完成的.我会使用套接字吗?只是在这里寻找一些方向.谢谢!
I'm interested in creating an iPhone app that can stream video from a central server, YouTube style. I was wondering if anyone has ever tried to do this before, what is the path of least resistant, existing APIs, etc? I really know nothing about how this is generally done. Would I be working with sockets? Just looking for some direction here. Thanks!
推荐答案
如果您已经启动并准备好流媒体服务器,那么实现一个弹出 youtube 风格的视频控制器就很容易了.
If you have the streaming server up and ready, it is quite easy to implement a video controller that pops up youtube-style.
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
).
You need to handle the controller that display the video player's view (which is self
in this case).
在 iOS 3.2+ MPMoviePlayerViewController 中让它更容易:
In iOS 3.2+ MPMoviePlayerViewController make it even easier:
NSString *videoURLString = @"http://path-to-iphone-compliant-video-stream";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentMoviePlayerViewControllerAnimated
是 MediaPlayer 对 FWViewController
的附加方法,你会在 iOS 3.2+ 中找到它,它负责创建一个视图控制器并将其推送到堆栈上,动画它带有从底部滑动的动画,就像在 youtube.app 中一样.
presentMoviePlayerViewControllerAnimated
is a MediaPlayer's additional method to FWViewController
that you will find in iOS 3.2+ and it takes care of creating a view controller and pushing it on the stack, animating it with a slide-from-bottom animation, as in youtube.app.
这篇关于编写一个应用程序将视频流式传输到 iPhone的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!