AVAsset does not recognize NSURL - Crashing - iOS

I am making an iOS application. One of its functions is that it can save recordings and save audio files.

To save the URL of the recorded audio files, I save them in NSUserDefaults as filePaths as follows:

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 a recorded file. But I have a problem with urls ...

The example in "FVSoundWaveDemo" loads the locally imported file as follows:

NSString* filename = [NSString stringWithFormat:@"song1.m4a"];
NSURL* url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:filename ofType:nil]];
_soundWaveView.soundURL = url;

You see a bit with "song1.m4a", well, I want to replace it and make the application use the file URL instead. Like the filePath url that I displayed above in my question.

I tried all kinds of things, for example, trying to "convert" filePath to a regular URL and trying to use AVAssets, etc. But all I'm trying is just causing this error:

The application terminated due to an unreported exception "NSRangeException", reason: "*** - [__ NSArrayM objectAtIndex:]: index 0 outside for an empty array

And this is because the library I use uses AVAssets like this:

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 can I get AVAsset to work with filePath url?

, , , NOT , Xcode.

, , , .

, .

+4
2

. , :

1) fileURLWithPath URLWithString :

NSURL *assetURL = [NSURL fileURLWithPath:passURL];
AVURLAsset *asset = [AVURLAsset assetWithURL:assetURL];

2) , URL- , NSString, :

:///var/mobile/Containers/Data/Application/17F8E799-D7E1-4B3C-9DFE-7BA48E346314/Documents/recordName.aif

, - AVPlayer. , URL-, "file:///" . , , , NSURL :

    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath_ = [searchPaths objectAtIndex:0];
    NSString *pathToSave = [documentPath_ stringByAppendingPathComponent:@"audioName.aif"];

"pathToSave" NSString , , , . , URL- :

/var/mobile/Containers/Data/Application/45ABF4BD-FA0E-43F7-B936-7DE29D8F28ED/Documents/23Feb2015_074118pm.aif

, :///. 1 .

, , .

+4

- ?

NSURL* assetURL = [NSURL URLWithString:@"file://your-file.aif"];
AVURLAsset* asset  = [AVURLAsset URLAssetWithURL:assetURL options:nil];
0

All Articles