是否可以在不停止 iPod 音乐的情况下在应用程序中播放声音?
现在我正在使用以下命令,但它会停止 iPod 音乐
soundPath =[[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
soundURL = [NSURL fileURLWithPath:soundPath];
mySound = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:nil];
[mySound prepareToPlay];
and then
[mySound play];
是的,可以,您可以使用以下代码
// setup session correctly
AVAudioSession *audiosession = [AVAudioSession sharedInstance];
[audiosession setCategory:AVAudioSessionCategoryPlayback error:nil];
OSStatus propertySetError = 0;
UInt32 mixingAllow = true;
propertySetError = AudioSessionSetProperty ( kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (mixingAllow),&mixingAllow);
NSError *error = nil;
[audiosession setActive:YES error:&error];
// play sound
NSURL *url = [NSURL fileURLWithPath:filePath];
AVAudioPlayer *audioplayer = [[[AVAudioPlayer alloc] initWithContentsOfURL:url error:&;error]autorelease];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)