为什么我的应用程序中的声音音量没有变化?

时间:2010-10-06 15:13:20

标签: iphone objective-c

我在我的应用程序中使用了以下代码,如果我从iPhone的按钮增加或减少音量,它仍然是相同的,但如果手机处于静音模式,语音将被静音。

代码:

-(void) playNote: (NSString *)Note type: (NSString *)type
{
    CFURLRef        soundFileURLRef;
    SystemSoundID   soundFileObject;
    CFBundleRef mainBundle;
    mainBundle = CFBundleGetMainBundle ();

// Get the URL to the sound file to play
soundFileURLRef  =  CFBundleCopyResourceURL (mainBundle,
         (CFStringRef)Note,
         (CFStringRef)type,
         NULL);


NSLog(@"%@\n", soundFileURLRef);
    // Create a system sound object representing the sound file
        AudioServicesCreateSystemSoundID (soundFileURLRef, &soundFileObject);

   AudioServicesPlaySystemSound (soundFileObject);
}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

在播放声音之前,您需要正确设置音频类别。

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
相关问题