A similar event occurred in my application that uses AVAudioPlayer. I tried with [NSURL URLWithString:path] and found that it could not open certain mp3 files. I searched for an error in a line like [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:path] fileTypeHint:AVFileTypeMPEGLayer3 error:&error] , but the error was just nil
However, it was resolved by replacing the url with [NSURL fileURLWithPath:path] .
In both cases, the path path NSString * @"/var/mobile/Containers/Data/Application/4D96D4AE-2ED4-40B0-85D2-230E1AFA90E7/Documents/01-AudioTrack 01.mp3" 0x1457a8f0 However, I do not know the reason, but now I have to be careful using [NSURL URLWithString:] .
PS. In a NSURL reference document, Apple stated the following:
IMPORTANT To create NSURL objects for file system paths, use fileURLWithPath: isDirectory: instead.
which explicitly specifies [NSURL fileURLWithPath:] should be used for an open file, although [NSURL URLWithString] also works in some cases.
gnuchoi Mar 14 '15 at 16:53 2015-03-14 16:53
source share