编写一个应用程序将视频传输到 iPhone

发布于 2024-09-04 21:18:06 字数 132 浏览 3 评论 0原文

我有兴趣创建一个 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

白芷 2024-09-11 21:18:06

如果您已经准备好了流媒体服务器,那么实现一个弹出 youtube 风格的视频控制器就非常容易了。

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];

presentMoviePlayerViewControllerAnimated 是 MediaPlayer 的 FWViewController 的附加方法,您将在 iOS 3.2+ 中找到它,它负责创建视图控制器和将其推入堆栈,使用从底部滑动的动画对其进行动画处理,如 youtube.app 中所示。

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];

You need to handle the controller that display the video player's view (which is self in this case).

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 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.

长发绾君心 2024-09-11 21:18:06

Apple 有一篇关于设置媒体流服务器端的详细文章:

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html

和最佳实践说明:

https://developer.apple.com/library/content/technotes/tn2224/_index.html

不仅它包含有关流服务架构和用于构建它的工具的信息,但也对此类服务必须满足一些要求以及对实时测试流的引用。

Apple has a detailed article about setting up server side for media streaming:

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StreamingMediaGuide/Introduction/Introduction.html

and Best Practices Note:

https://developer.apple.com/library/content/technotes/tn2224/_index.html

Not only it contains info about streaming service architecture and tools used to build it but also has some requirements to such kind of service that must be fulfilled and references to live test streams.

素食主义者 2024-09-11 21:18:06

使用此代码可使用低内存。关于流媒体视频....

-(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];
}

Use this code to use low memory. On streaming video....

-(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];
}
逐鹿 2024-09-11 21:18:06

QuickTime 视频已传输至手机。阻力最小的方法是使用媒体播放器控制器并将其指向流服务器上的流媒体文件。

QuickTime videos already stream to the phone. The path of least resistance would be to use the media player controller and point it to a streaming media file on a streaming server.

平生欢 2024-09-11 21:18:06

虽然现有的答案很好,但如果您需要使用非 HTTP 流(例如 mms 或 rtmp)或非 Apple 支持的音频/视频编解码器,事情会变得有点复杂。

我自己不是专家,但我一直在使用这个 VideoStreaming SDK 来解决这些问题,并且它使定制客户端变得更加容易(后台流、暂停流等)。如果您也有这些要求,可能值得一看。

While the existing answers are good, if you need to use non HTTP streams (mms or rtmp for example) or non Apple supported audio / video codecs, things get a bit more complicated.

I'm not an expert myself, but I've been using this VideoStreaming SDK to solve those problems, and it makes customizing the client much easier (background streaming, pausing streams, etc). Might be worth a look if you have those requirements as well.

愁杀 2024-09-11 21:18:06

2018年答案您可以使用AVPlayerViewController,因为自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];

2018 answer You can use AVPlayerViewController since MPMoviePlayerController is deprecated since iOS 9

    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];
假扮的天使 2024-09-11 21:18:06

以下是一些不错的流媒体视频库和示例:

Here are some good libraries for streaming video with examples:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文