开发者

AudioServicesCreateSystemSoundID not playing mp3 files

开发者 https://www.devze.com 2023-04-08 11:21 出处:网络
Can anyone answer how to play mp3 files using AudioServicesCreateSystemSoundID()? I tried but not working.

Can anyone answer how to play mp3 files using AudioServicesCreateSystemSoundID()? I tried but not working.

I have used the following code snippet for playing mp3

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

soundFileURLRef 开发者_StackOverflow中文版= (CFURLRef) [soundURL retain];

// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID ( soundFileURLRef,&soundFileObject);


I had the same problem using this example. Maybe your sound sample is to big/long.

NSString *path = [[NSBundle mainBundle] pathForResource:@"tap" ofType:@"aif"];

NSURL *url = [NSURL fileURLWithPath:path];AudioServicesCreateSystemSoundID((__bridge CFURLRef)url, &mBeep);

AudioServicesPlaySystemSound(mBeep);

It was not working because the audio file was to long. I tried with the sound from the apple example http://developer.apple.com/library/ios/#samplecode/SysSound/Introduction/Intro.html "tap.aif" and it worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消