I am making an iOS app. One of its features is that it can save record and save audio files.
In order to save the URL's of the recorded audio files, I storing them in NSUserDefaults as filePaths like so:
file:///var/mobile/Containers/Data/Application/17F8E799-D7E1-4B3C-9DFE-7BA48E346314/Documents/recordName.aif
I am using a library called "FVSoundWaveDemo" to try and display a sound wave for the recorded file. But I have a problem with URL's...
The example in "FVSoundWaveDemo" loads a locally imported file like so:
NSString* filename = [NSString stringWithFormat:@"song1.m4a"];
NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:nil]];
_soundWaveView.soundURL = url;
You see the bit with "song1.m4a", well I want to replace that and get the app to use a filePath URL instead. Like the filePath URL I displayed above in my question.
I have tried all sort of things like trying to "convert" the filePath into a normal URL and trying to use AVAssets and so on. But everything I try just comes up with this error:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
And this is because the library I am using, uses AVAssets like so:
AVAssetReader* reader = [[AVAssetReader alloc] initWithAsset:songAsset error:&error];
AVAssetTrack* songTrack = [songAsset.tracks objectAtIndex:0];
NSDictionary* outputSettingsDict = [[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:8],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsNonInterleaved,
nil];
So how an earth do I get an AVAsset to just work with a filePath URL?
Remember I am trying to get it to view a recorded audio file saved by the app, NOT a locally imported audio file which a developer can add into the Xcode project.
I have been stuck on this for days now, if you can help me, that would be much appreciated, thanks.
Thanks for your time, Dan.