0

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)

Community
  • 1
  • 1
mrlowalowa
  • 23
  • 6

1 Answers1

3

OSStatus = 0 means "no Error", which means that the function AudioServicesCreateSystemSoundID did succeed.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • But why does the application crashes all the time when I press the button ( Which is connectet to - (IBAction)playtrack ) ?? Do I need to add "(id)sender" to this methode? – mrlowalowa Jan 12 '13 at 18:01
  • @mrlowalowa: Do you get any error message when the application crashes? – Martin R Jan 12 '13 at 18:19
  • I got some wich where directed to autorelease in main But I had a different IBAction running as well in this ViewControll.C file. After I put it together with the other button I heard the sound... I created 3 other methodes which are working fine, but they aren't affacted by a differnet button or so. Maybe it overloaded if I have there 2 different IBActions in.. – mrlowalowa Jan 15 '13 at 15:52