如何将视频从 url 保存到磁盘,以及如何在缓冲后开始播放?
第一个问题是,给定 mp4 视频的 url,如何将该文件保存到磁盘?后续操作是在保存时,我可以在将部分视频缓冲到磁盘后开始播放,还是必须等待整个文件被写入,然后:
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
使用本地文件的路径。
谢谢, 山姆
First question is, given a url to an mp4 video, how can I save that file to disk? The followup to that is while its saving, can I begin playback after its buffered some of the video to disk or do I have to wait for the entire file to be written and then:
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
using the path to the local file.
Thanks,
Sam
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MPMoviePlayerController
将开始将电影下载到其自己的缓存中,并在下载足够的数据后立即开始播放视频。AFAIK 无法控制下载,例如将其保存到您指定的已知文件中。
The
MPMoviePlayerController
will start downloading the movie to it's own cache and will start playing the video as soon as enough data has been downloaded.AFAIK there is no way to control the download and to for example save it to a known file that you specify.
1.使用 NSURLDownload 或 NSURLConnection 可以实现您的请求。
2.播放下载的文件或本地文件,就像播放url链接
[NSURL fileURLWithPath:yourlocalpath];
1.Using NSURLDownload or NSURLConnection can implement your request.
2.play downloaded file or localfile, just like play url link
[NSURL fileURLWithPath:yourlocalpath];
没有简单的方法可以做到这一点,但您可以使用
NSURLConnection
下载文件并从您在设备上本地运行的专用 HTTP 服务器重新提供该文件(您的服务器将保存该文件到磁盘并保留部分下载供MPMoviePlayerController
访问)There is no simple way to do this, but you could use
NSURLConnection
to download the file and re-serve it from a specialized HTTP server of your making running locally on the device (your server would save the file to disk and reserve up the partial download forMPMoviePlayerController
to access)