简体   繁体   中英

iphone simulator 3.2 AvAudioPlayer fileURL Issue

I am getting a weird problem with avaudioPlayer. It work fine when I run iphone simulator 4.0, 4.1 and 4.2. It also works fine when I run ipad simulator 4.2 but when I run ipad simulator 3.2 then it crashes because AVAudioPlayer code has a fileURL which is Null.

Here is my code.

   NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name
                                                     ofType:@"mp3"];

// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];

I am using AVFoundation Framework with weak link for making it iOS3 compatible. it is getting globalMP3Name (1.mp3) correctly so filePath of 1.mp3 should not be null. FileURL is working with other simulators but only 3.2 is crashing.

Here is the error msg from console.

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter'
2011-06-27 18:51:57.092 Stack: (
45475920,
46633772,
45213451,
45213290,
1135303,
18960,
3038446,
3535934,
3545280,
3540077,
3165672,
3057219,
3088856,
53191036,
44755100,
44751016,
53184669,
53184866,
3081074,
10148,
10037
)
terminate called after throwing an instance of 'NSException'

How do I fix it?

The name of the resource shouldn't have the extension, yours should be called only @"1"

Look the error message

reason: ' *** -[NSURL initFileURLWithPath:]: nil string parameter

, so you may want pause at

NSString *filePath = [[NSBundle mainBundle] pathForResource:appDelegate.globalMP3Name ofType:@"mp3"];

po appDelegate.globalMP3Name to see what happen.

I think it just is nil.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM