作为主题...有可能吗?
谢谢
再次,我已经附上如下代码,请检查哪一步是错误的.thanks。
//@step
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
OSStatus error = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory);
if (error)
printf("ERROR AudioSessionSetProperty ! %d\n", error);
//@step
NSString* filePath = @"AlarmClockBell.caf";
[Util restoreResourceFile:filePath];
filePath =[Util getFileFullPathFromSysDoc:filePath];
NSURL *soundFileURL = [NSURL fileURLWithPath:filePath];
NSError* error ;
AVAudioPlayer * audioPalyer = [[AVAudioPlayer alloc] initWithContentsOfURL: soundFileURL error: &error];
if (nil == audioPalyer)
{
AppTrace3(self, @"Faild to play", soundFileURL, error);
return FALSE;
}
[audioPalyer prepareToPlay];
[audioPalyer setVolume: 5 ];
[audioPalyer setDelegate: self];
audioPalyer.numberOfLoops = 10;
[audioPalyer play];谢谢..。
发布于 2010-05-01 17:41:44
如果你查看音频会话类别下的文档,你会发现你可以设置一些模式来告诉系统你的应用程序计划如何使用音频。默认值为AVAudioSessionCategorySoloAmbient,它跟踪振铃/静音开关和屏幕锁定。
要让你的应用忽略振铃/静音开关设置,你可以尝试更改类别:
#import <AudioToolbox/AudioToolbox.h>
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);如果你想让iPod音频在后台继续播放,你还需要勾选kAudioSessionProperty_OverrideCategoryMixWithOthers。
发布于 2013-10-18 21:45:09
从iOS 6开始,有一种比Ramin's answer更紧凑的替代方法。
#import <AVFoundation/AVFoundation.h>
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];要允许其他应用程序的背景音频继续播放,请添加AVAudioSessionCategoryOptionMixWithOthers选项:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:nil];在苹果的AVAudioSession Class Reference上有更多的细节。
发布于 2010-05-01 14:50:52
肯定是这样的,我已经玩过几款游戏了(即使是在静音模式下)也能播放声音。不幸的是,这是在试图在课堂上偷偷玩游戏时发现的。
至于如何真正做到这一点,我真的不知道。
https://stackoverflow.com/questions/2749066
复制相似问题