开发者

why the volume of sounds does not change in my app?

I used code below in my application, and if I increase or decrease the volume from the iPhone's button it's still the same, but if the phone is in silent mode the voice will be muted.

The code:开发者_运维知识库

-(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);
}

What am I doing wrong?


You need to set your Audio Category properly before playing back sounds.

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜