Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Code:

AVQueuePlayer+initWithAppAudioFiles.m
Code:
#import "AVQueuePlayer+initWithAppAudioFiles.h"

@implementation AVQueuePlayer (initWithAppAudioFiles)
+(AVQueuePlayer *)initWithAppFiles:(NSArray *)fileNames extension:(NSString *)extension
{
    NSMutableArray *fileURLs;
    for (NSString *fileName in fileNames)
    {
        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension];
        [fileURLs addObject:fileURL];
    }
    AVQueuePlayer *queuePlayer = [[AVQueuePlayer alloc] initWithItems:fileURLs];
    return queuePlayer;
}
@end
 
Last edited:

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Looks like the problem lies with the following code:

Code:
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:fileName withExtension:extension];

Even though the file names and extensions are correct, fileURL remains nil.
 

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
OK, it turns out that the audio file was not located under "Copy Build Resources," which is located under "Build Phases." This is why URLForResource returned nil. Thanks, Zaph from Stack Overflow!
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
How did you add the files to your project? When using the File > Add Files to "ProjectName"... option (or dragging-and-dropping), you should make sure you have checked the proper target in the "Add to targets" section of the dialog. If so, this will automatically add the file to the Copy Bundle Resources settings.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.