Giter Club home page Giter Club logo

Comments (6)

bobmccune avatar bobmccune commented on September 13, 2024

Your code looks correct. If playback is not resuming when the interruption ends, I'm guessing "options" is not equal to AVAudioSessionInterruptionOptionShouldResume.

from learning-av-foundation.

sunyazhou13 avatar sunyazhou13 commented on September 13, 2024

options always is AVAudioSessionInterruptionOptionShouldResume

from learning-av-foundation.

sunyazhou13 avatar sunyazhou13 commented on September 13, 2024

something wrong happen in playTime

from learning-av-foundation.

sunyazhou13 avatar sunyazhou13 commented on September 13, 2024

you can have a try to run

- (void)handleInterruption:(NSNotification *)notification {
    NSDictionary *info  = notification.userInfo;
    AVAudioSessionInterruptionType type = [info[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
    
    if (type == AVAudioSessionInterruptionTypeBegan) {
        //AVAudioSessionInterruptionTypeBegan
        [self stop];
        if ([self.delegate respondsToSelector:@selector(playbackStopped)]) {
            [self.delegate playbackStopped];
        }
    } else {
        //AVAudioSessionInterruptionTypeEnd
        AVAudioSessionInterruptionOptions options = [info[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
        if (options == AVAudioSessionInterruptionOptionShouldResume) {
            [self play];
            if (self.delegate) {
                [self.delegate playbackBegan];
            }
        }
        NSLog(@"%lu",(unsigned long)options);
        
    }
}

from learning-av-foundation.

bobmccune avatar bobmccune commented on September 13, 2024

It appears Apple must have changed some behavior (at least in iOS 10.3 beta, which is what I'm running). Previously, calling play on an AVAudioPlayer would always reactivate the audio session. That doesn't appear to be the case. The fix is it manually reactivate your audio session before calling play (e.g. [[AVAudioSession sharedInstance] setActive:YES error:nil];).

from learning-av-foundation.

sunyazhou13 avatar sunyazhou13 commented on September 13, 2024

Oh cool

I used this code [[AVAudioSession sharedInstance] setActive:YES error:&error]; it works

/**
 音频被打断 通知事件

 @param notification 音频信息
 */
- (void)handleInterruption:(NSNotification *)notification {
    NSDictionary *info  = notification.userInfo;
    AVAudioSessionInterruptionType type = [info[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue];
    
    if (type == AVAudioSessionInterruptionTypeBegan) {
        //AVAudioSessionInterruptionTypeBegan
        [self stop];
        if ([self.delegate respondsToSelector:@selector(playbackStopped)]) {
            [self.delegate playbackStopped];
        }
    } else {
        //AVAudioSessionInterruptionTypeEnd
        AVAudioSessionInterruptionOptions options = [info[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue];
        if (options == AVAudioSessionInterruptionOptionShouldResume) {
            NSError *error = nil;
            [[AVAudioSession sharedInstance] setActive:YES error:&error];
            [self play];
            if (self.delegate) {
                [self.delegate playbackBegan];
            }
            if (error) { NSLog(@"Active error:%@",error); }
        }
        NSLog(@"%lu",(unsigned long)options);
        
    }
}

Very thanks , your book wrote very good and I've ever read like this

from learning-av-foundation.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.