0

我有一个 iOS 应用程序,它使用了许多不同的音频文件,记录在应用程序中并保存。我已经导入了 AVFoundation 框架,但是我仍然得到错误:

选择器“URLAssetWithURL”没有已知的类方法

这是我的代码:

AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:audioFiles[indexPath.row]]];
waveformView.asset = asset;

audioFiles 数组内部是一个本地 URL,如下所示:

file:///var/mobile/Containers/Data/Application/6B35F9EA-1896-4989-91AF-06850B74B2E9/Documents/record_sound_1.aif

我究竟做错了什么?

4

2 回答 2

2

根据https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVURLAsset_Class/index.html上的类参考

类方法有两个参数,URL 和一些选项。改成:

AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:audioFiles[indexPath.row]] options:nil];
waveformView.asset = asset;

我希望 XCode 的自动完成和突出显示很明显你正在使用一种不存在的方法......

于 2015-02-20T22:27:35.080 回答
0

您在该方法调用中缺少第二个参数。URLAssetWithURL:options:声明如下:

+ (AVURLAsset *)URLAssetWithURL:(NSURL *)URL options:(NSDictionary *)options

在您的通话中,您缺少options参数。

于 2015-02-20T22:28:37.987 回答