0

I have an iOS app which uses a lot of different audio files recorded in the app and saved. I have imported AVFoundation framework, however I still get the error:

No known class method for selector 'URLAssetWithURL'

Here is my code:

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

Inside the audioFiles array is a local URL like the following:

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

What am I doing wrong?

Marc Bollinger
  • 3,109
  • 2
  • 27
  • 32
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98

2 Answers2

2

As per the class reference at https://developer.apple.com/library/mac/documentation/AVFoundation/Reference/AVURLAsset_Class/index.html

the class method takes two parameters, the URL and some options. Change to:

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

I would expect XCode's autocompletion and highlighting make it obvious that you were using a method that didn't exist...

RobP
  • 9,144
  • 3
  • 20
  • 33
  • Great thank you very much sir. Actually Xcode didn't come up with any popup .... But anyway thanks for your help. – Supertecnoboff Feb 20 '15 at 22:34
  • It occurs to me that you'll get better checking from the IDE if you type your variable more specifically. Unless there's a reason not to, declare `asset` as `AVURLAsset *asset` rather than `AVAsset *asset` and see what XCode tells you then. – RobP Feb 20 '15 at 22:35
0

You are missing the second argument in that method call. URLAssetWithURL:options: is declared like:

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

In your call you are missing the options parameter.

Midhun MP
  • 103,496
  • 31
  • 153
  • 200