2016-08-07 13 views
0

私はアプリケーションで初めてMPMusicPlayerControllerクラスとAVSpeechSynthesizerクラスを使用しています。 MPMusicPlayerControllerを使用して音楽を再生し、ランナーを(AVSpeechSynthesizerを使用して)5分ごとに統計情報で更新する実行中のアプリです。それはうまくいきますが、音楽と放送は同じ音量で再生されているため、統計情報を聞くのが難しい場合がありますので、統計情報が放送されている間に音楽量を下げてください。以下のコードは、統計が放送を開始するときに音楽量を減らすためにのみ機能しますが、統計放送が終了した後は音楽を再開しません。これはもちろん私がしたいことです。私はこのポストSetting iOS MPMusicPlayerController volume relative to AVAudioPlayerからこのソリューションを使用しています。 私のコードは以下の通りです:ダッキングを実装しようとしているMPMusicPlayerControllerとAVSpeechSynthesizer

- (void)setAudioSessionWithDucking:(BOOL)isDucking 
    { 
    AudioSessionSetActive(NO); 

    UInt32 overrideCategoryDefaultToSpeaker = 1; 
    AudioSessionSetProperty  (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof  (overrideCategoryDefaultToSpeaker), &overrideCategoryDefaultToSpeaker); 

    UInt32 overrideCategoryMixWithOthers = 1; 
    AudioSessionSetProperty  (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof  (overrideCategoryMixWithOthers), &overrideCategoryMixWithOthers); 

    UInt32 value = isDucking; 
    AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck,  sizeof(value), &value); 

    AudioSessionSetActive(YES); 
} 

- (void)updateLabels 
{ 

if(fmod(mins,5) == 0){ 
[self setAudioSessionWithDucking:YES]; 

    AVSpeechUtterance *utterance = [AVSpeechUtterance 
            speechUtteranceWithString:newText]; 
    AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init]; 

    utterance.rate = 0.45; 
    utterance.pitchMultiplier = 0.95; 
    utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"]; 
    utterance.volume = 1.0; 

    [synth speakUtterance:utterance]; 

[self setAudioSessionWithDucking:NO]; 
     } 
} 

答えて

0

使用これは、彼らがオーディオの再生を再開すること他のアプリを教えて:あなたは再開したいオーディオが独自のアプリから来る場合

-(void)notifyIOSthatOtherAppsCanResumeAudioPlayback{ 
    NSError *err; 
    [indigoAudioSession setActive: NO 
        withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation 
         error: &err]; 
    if(err!=nil){ 
     NSLog(@"audioIsFreeNotificationForIOS ERROR: %@",err.description); 
    } 
} 

を、あなたはそれを伝えることができます

- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance{ 
    playSomeMusic(); 

}

:このデリゲートメソッドから再生を再開します
関連する問題