Couldn't play system sound after switching to iOS 5

前端 未结 4 1361
失恋的感觉
失恋的感觉 2020-12-16 00:57

This is how I played a beep sound effect in iOS 4:

SystemSoundId beepOnSoundId;

CFURLRef soundUrl = CFBundleCopyResourceURL(
    CFBundleGet         


        
4条回答
  •  执念已碎
    2020-12-16 01:46

    In my Constructor:

    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
    UInt32 doSetProperty = 1;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(doSetProperty), &doSetProperty);
    [[AVAudioSession sharedInstance] setActive: YES error: nil];
    NSURL* musicFile  = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                                       pathForResource:@"video-sent"
                                                       ofType:@"caf"]];
    self.sentSound = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
    [self.sentSound prepareToPlay];
    

    The function playSentSound

    - (void)playSentSound
    {
        DLog(@"PLay Sound %@", self.sentSound);
        [self.sentSound play];
    }
    

    then later in the code i just call it

    [self playSentSound];
    

    The key here are the first 4 lines ... ;-)

提交回复
热议问题