gpt4 book ai didi

objective-c - 在 iOS 上播放实时流中的视频,同时将流保存到磁盘

转载 作者:可可西里 更新时间:2023-11-01 05:14:34 26 4
gpt4 key购买 nike

我已经研究这个主题一段时间了,但我真的想不通如何才能做到这一点。假设我们有一个来自 HTTP 流的视频,我希望能够在我的应用程序中播放该视频,同时该视频也保存在磁盘上。我知道我可以使用 AVFoundation 或 MediaPlayer 框架播放视频,并且可以通过 NSURLRequest 加载文件/流。

不过这是两个不同的过程,需要加载视频两次。我不知道是否以及如何将这两者结合起来。这可能/可行吗?

最佳答案

这是可能的。但是,对于您的 YouTube 视频,如果您喜欢我不想推荐。因为遵循 Youtbe TOS。

由于以下原因:

22.4

We found that your app contains information that may allow its users to download YouTube content, which is not in compliance with the YouTube Terms of Service.

"...You shall not download any Content unless you see a "download" or similar link displayed by YouTube on the Service for that Content. You shall not copy, reproduce, distribute, transmit, broadcast, display, sell, license, or otherwise exploit any Content for any other purposes without the prior written consent of YouTube or the respective licensors of the Content. YouTube and its licensors reserve all rights not expressly granted in and to the Service and the Content."

另请参阅以下站点问题。这非常重要。您肯定需要阅读。

http://www.iphonedevsdk.com/forum/business-legal-app-store/88260-youtube-downloader.html


无论如何,现在我将告诉您如何实现它们。

a. Streaming Service is not difficult to implement. According to Apple's sample code can be easily implemented. Please note the following. this using a AVPlayer. at 3G, Wifi i tested. it' fine. how to test? upload to video your server or get video link. and copy and paste in source code xib textField.

StitchedStreamPlayer

b. Video downloads are available at the same time. I will recommend AFNetworking. ARC support for it. so if apps state is the background, download continue.

AFNetworking

如何下​​载?

NSURLRequest *request = [NSURLRequest requestWithURL:"your_http_video_url" cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:20];

AFURLConnection *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [[docPaths objectAtIndex:0] stringByAppendingPathComponent:"your_save_video_name.mp4"];

operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];

[operation setDownloadProgressBlock:^(NSInteger bytesRead, long long
totalBytesRead, long long totalBytesExpectedToRead)
{
//do stuff. about upadte progressbar...
}];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"downloadComplete"); // show alertView to user.
}];
[operation start];

关于objective-c - 在 iOS 上播放实时流中的视频,同时将流保存到磁盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11926649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com