I got a very similar problem like here: link In ViewController.h file I added this:
#import <UIKit/UIKit.h>
#include <AudioToolbox/AudioToolbox.h>
@interface ViewController : UIViewController
@property SystemSoundID outSystemSoundID1;
@end
and in ViewController.m that:
#import <ViewController.h>
@interface ViewController ()
- (IBAction)playtrack;
@end
@implementation ViewController
@synthesize outSystemSoundID1;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1000Hz-0-4sec" ofType:@"wav"];
NSURL *url1 = [NSURL fileURLWithPath:path1];
//CFURLRef lol = (CFURLRef)objc_unretainedPointer(url1);
//AudioServicesCreateSystemSoundID( lol, &outSystemSoundID1);
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)url1, &outSystemSoundID1);
NSLog(@"AudioServicesCreateSystemSoundID status = %ld", status);
}
- (IBAction)playtrack {
AudioServicesPlaySystemSound (outSystemSoundID1);
}
@end
The Sound file I want to Play is under Supporting Files.
The OSStatus says:
AudioServicesCreateSystemSoundID status = 0
I tried for the CFURLRef lots of different combinations like you can see in the out-commented part.
Maybe my file is just not supported? After I got the solution for this I want to initialize 3 Sound files in aif Format with this way.
Hope you can help me! Thanks :)
I have ARC activated and I'm on iOS 6.0.1 (iPhone)
OSStatus = 0
means "no Error", which means that the function AudioServicesCreateSystemSoundID
did succeed.