Code Monkey home page Code Monkey logo

Comments (13)

ryanheise avatar ryanheise commented on July 21, 2024 1

Thanks for testing! This is now published in 0.0.9.

from audio_session.

jjb182 avatar jjb182 commented on July 21, 2024 1

Hi snaeji, I think that you have likely dealt with some of the issues I'm facing trying to get the audio session to become active again after a call--on iOS. This is likely not the most appropriate place to post this, but I'm pulling my hair our over here. I also can't find an email for you anywhere. If you can reach out to me I will thank you 1 million times! (give or take) [email protected]

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

I really appreciate that you found this.

I will add a boolean wasSuspended field to AVAudioSessionInterruptionNotification so that the value gets exposed to the Dart layer, and then I can implement your workaround in Dart for the iOS version of becomingNoisyEventStream.

from audio_session.

snaeji avatar snaeji commented on July 21, 2024

That sounds great!

I'm just glad that I can contribute. Our app has been using audio_service on Android for a year now and it is working great. And with the latest development I feel that it's now stable enough to take over our native iOS.

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

I have just implemented this in the latest commit. I would be interested to know if it works for you. Even though I haven't pushed my changes to just_audio yet (which would prevent it from crashing with this new version of audio_session), I think you will still be able to confirm whether this feature works before a dispose occurs and crashes things.

I will let you know once the just_audio fix is also available.

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

The just_audio changes are now available for testing. While the various git versions can be added to your pubspec, you'll probably also need to add a dependencyOverrides section to force all of the transitive dependencies to also use those git versions.

from audio_session.

snaeji avatar snaeji commented on July 21, 2024

Great work! I'll get on it first thing Monday morning.

from audio_session.

snaeji avatar snaeji commented on July 21, 2024

I found a small bug but otherwise everything seems to work great! Running the newest commit from just_audio and audio_session.

The error output:

2020-10-12 12:20:38.498250+0000 Runner[915:53045] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'
*** First throw call stack:
(0x19bd3e5ac 0x1afdb842c 0x19bdad4cc 0x19bdaaec4 0x19bc273b0 0x19bc21ef0 0x104c473c0 0x19bc9d764 0x19bc9d718 0x19bc9ccd4 0x19bc9c6a0 0x19cf305f4 0x1a35548c8 0x1a354e064 0x104e87b68 0x104e895f0 0x104e98890 0x19bcbb1e4 0x19bcb53b4 0x19bcb44bc 0x1b2739820 0x19e658734 0x19e65de10 0x10237d618 0x19b97be60)
libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]'
terminating with uncaught exception of type NSException

I think it's just that we have to ensue that wasSuspended is never null. So we probably have to init it as @(0) and add a check for valueForKey like in the example below:

- (void) audioInterrupt:(NSNotification*)notification {
    NSNumber *interruptionType = (NSNumber*)[notification.userInfo valueForKey:AVAudioSessionInterruptionTypeKey];
    NSNumber *wasSuspended = @(0);
    if (@available(iOS 10.3, *)) {
        if ([notification.userInfo valueForKey:AVAudioSessionInterruptionWasSuspendedKey]) {
            wasSuspended = [notification.userInfo valueForKey:AVAudioSessionInterruptionWasSuspendedKey];
        }
    }

    NSLog(@"audioInterrupt");
    switch ([interruptionType integerValue]) {
        case AVAudioSessionInterruptionTypeBegan: {
            [self invokeMethod:@"onInterruptionEvent" arguments:@[@(0), @(0), wasSuspended]];
            break;
        }
        case AVAudioSessionInterruptionTypeEnded: {
            if ([(NSNumber*)[notification.userInfo valueForKey:AVAudioSessionInterruptionOptionKey] intValue] == AVAudioSessionInterruptionOptionShouldResume) {
                [self invokeMethod:@"onInterruptionEvent" arguments:@[@(1), @(1), wasSuspended]];
            } else {
                [self invokeMethod:@"onInterruptionEvent" arguments:@[@(1), @(0), wasSuspended]];
            }
            break;
        }
        default:
            break;
    }
}

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

Hmm, I guess that means valueForKey is returning nil sometimes which was not expected. I'd prefer not to lose information, so I'd like to pass [NSNull null] through the method channel in this case:

    NSNumber *wasSuspended = nil;
    if (@available(iOS 10.3, *)) {
        wasSuspended = [notification.userInfo valueForKey:AVAudioSessionInterruptionWasSuspendedKey];
    }
    if (wasSuspended == nil) {
        wasSuspended = [NSNull null];
    }

I'll quickly make this change now.

And in hindsight, I would prefer to have done for AVAudioSessionInterruptionTypeKey too, and will probably fix that at some point.

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

I've made the above change in the latest commit, hopefully this will correctly pass through to Dart where it considers the null value.

from audio_session.

snaeji avatar snaeji commented on July 21, 2024

Ahh i see, i just googled it and found out that you can pass NSNull null and not nil. Will check it out now.

from audio_session.

snaeji avatar snaeji commented on July 21, 2024

Ran into some Fabric issues so i was delayed a bit.. but the changes are working. Great work!

So now with the latest commits in just_audio and audio_session i haven't found any issues.

from audio_session.

ryanheise avatar ryanheise commented on July 21, 2024

It looks like I have made a mistake with the nullsafety version by not making wasSuspended nullable.

Changing it to nullable is technically a breaking change but breaking change version bumps should be avoided as much as possible with audio_session since it will cause a wave of dependency version constraint problems for other packages.

Maybe since this breaking change is in an undocumented API and most people will be going through the public AudioSession class which will not itself break, I might be able to get away with a minor version bump.

Would this cause issues for you?

from audio_session.

Related Issues (20)

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.