简体   繁体   English

将音频和视频转换为NSData

[英]Converting audio and video to NSData

I would like to confirm what the recommended ways are to convert audio and video files into NSData objects. 我想确认将音频和视频文件转换为NSData对象的推荐方法。 Is + dataWithContentsOfFile: the best way to do this? + dataWithContentsOfFile:最好的方法吗?

对于视频,因为你唯一拥有的是URL,是的dataWithContentsofFile可能是获取数据的最佳方式。

That's not a conversion, and it doesn't matter what's in the file—video, audio, text, game data, random garbage, or nothing at all. 那不是转换,文件 - 视频,音频,文本,游戏数据,随机垃圾或者什么都没有,这无关紧要。 NSData just gives you the plain bytes; NSData只提供普通字节; you'll need to pass either the data or the original pathname or URL to a higher-level class (such as UIImage, AVAudioPlayer, or MPMoviePlayerController) to actually show or play it. 您需要将数据或原始路径名或URL传递给更高级别的类(例如UIImage,AVAudioPlayer或MPMoviePlayerController)才能实际显示或播放它。

In fact, MPMoviePlayerController does not even accept a data object—it only accepts URLs. 实际上,MPMoviePlayerController甚至不接受数据对象 - 它只接受URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM