开发者

Make AVFoundation not stop iPod music

开发者 https://www.devze.com 2023-03-29 13:36 出处:网络
Im using the AVFoundation framework to play sound files. The problem im having is that its stopping music from playing when the audio file gets used, im not saying play both files continuously, but开发

Im using the AVFoundation framework to play sound files. The problem im having is that its stopping music from playing when the audio file gets used, im not saying play both files continuously, but开发者_如何学JAVA play the sound file, then pick up the ipod music right where it left off. Is there any way i can use AVFoundation is this kind of way? or is there a better framework for it?

Here is what my code looks like:

click = [NSURL fileURLWithPath:[NSString stringWithFormat:@"@/Click.WAV", [[NSBundle mainBundle] resourcePath]]];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:click error:nil];
audioPlayer.numberOfLoops = 1;
[click release];
[audioPlayer play];

This code works completely fine, i had to type it out so ignore any problems that there might be with it.

Thanks, Jacob


You can use the AVAudioSession class to change the audio "category" of your app: thus you can allow it to play on top of the iPod music. Use the -setCategory:error: method, and you will probably want to use AVAudioSessionCategoryAmbient. More info can be found in the Audio Session Programming Guide.

0

精彩评论

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