English 中文(简体)
iOS: 当无声模式打开时无法播放我的声音
原标题:iOS: Unable to play my sounds when silent mode on

所以我已经谈了大部分相关的问题,我能找到,但我仍然无法在沉默中播放音频。我相信,这可能是我犯的一个小错误。

我试图播放一个小警告声音。 这是我在 view Did Load 方法中的代码 :

AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);

这是当我需要播放音频剪辑时我叫的手法

-(void)playAudioClip:(CFStringRef)clip{

CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFile = CFBundleCopyResourceURL(mainBundle, clip, CFSTR("wav"), NULL);

//Supposed to make sound playable even when silent right?
UInt32 soundType = kAudioSessionCategory_MediaPlayback; 
UInt32 soundID;

AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(soundType), &soundType);
AudioServicesCreateSystemSoundID(soundFile, &soundID);
AudioServicesPlaySystmSound(soundID);
}

我从SO那里得到了大部分这些, 并在苹果程序指南中确认了这一点。 我已经尝试将两个用途的 < code> Uint32 合并为两个用途, 但是这也没有做任何事情, 仍然没有在锁定/ 沉默模式下玩耍 。 有什么想法吗?

最佳回答

系统声音在静默模式下不会播放 。 (如名字所示) 如果您需要播放音响而静默, 您需要使用不同的方法, 如媒体播放器或其他音频方法 。 请查看 苹果 播放音乐的示例 。

问题回答

暂无回答




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签