如何将AVAsset转换为NSData或将其保存到文件管理器 [英] How to convert AVAsset to NSData or save it to file manager
问题描述
我正在尝试使用 AVAsset
来录制音频文件,然后在第一次将它存储在 NSFileManager
之后之后将其转换为nsdata i Call API来存储它。
I am trying to do that using AVAsset
to record Audio file and then after first i store it on NSFileManager
and after that by convert it to nsdata i Call API to store it.
我成功创建 AVAsset
录制使用 SCPlayer
的第三方类进行文件播放。
I am successful to Create AVAsset
recording file and play it using third party Class that is SCPlayer
.
现在的问题是我不知道如何使用 AVAsset
文件将其保存在文件管理器中,然后在调用API之后将其转换为 NSData
。
Now problem is that i don't know how to Use AVAsset
file for save it in file manager and then after call API to sent it by converting it to NSData
.
有没有办法将 AVAsset
转换为 NSData
? ??
Is any way to convert AVAsset
to NSData
???
请帮助...
推荐答案
你可以做以下内容:
- 使用
AVAssetExportSession
导出AVAsset
文件
路径网址的对象。 -
将其转换为
NSData
使用它的dataWithContentsOfURL
方法。
- Use
AVAssetExportSession
to export yourAVAsset
object to a file path URL. Convert it to
NSData
using itsdataWithContentsOfURL
method.
NSURL *fileURL = nil;
__block NSData *assetData = nil;
// asset is you AVAsset object
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetHighestQuality];
exportSession.outputURL = fileURL;
// e.g .mov type
exportSession.outputFileType = AVFileTypeQuickTimeMovie;
[exportSession exportAsynchronouslyWithCompletionHandler:^{
assetData = [NSData dataWithContentsOfURL:fileURL];
NSLog(@"AVAsset saved to NSData.");
}];
执行任何操作后,不要忘记清理输出文件它;)
Don't forget to clean up the output file after doing whatever you need to do with it ;)
这篇关于如何将AVAsset转换为NSData或将其保存到文件管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!