Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
869 stars 568 forks source link

[BUG] Calling closeAudioSession throws a platform exception #370

Closed chi-tea-72 closed 4 years ago

chi-tea-72 commented 4 years ago

Flutter Sound Version :


Severity

Halts code execution. Unable to get past the following line in my code to execute code afterwards: await _audioRecorder.closeAudioSession();


Platforms you faced the error

A real android device.


Logs

(This is very important. Most of the time we cannot do anything if we do not have information on your bug) E/MethodChannel#com.dooboolab.flutter_sound_recorder(24648): Failed to handle method call E/MethodChannel#com.dooboolab.flutter_sound_recorder(24648): java.lang.NullPointerException: Attempt to invoke interface method 'void com.dooboolab.fluttersound.RecorderInterface._stopRecorder()' on a null object reference

From the stack trace we start here: https://github.com/dooboolab/flutter_sound/blob/master/lib/src/flutter_sound_recorder.dart#L144 Finally the crash occurs here: https://github.com/dooboolab/flutter_sound/blob/master/lib/src/session.dart#L51


Describe the bug A clear and concise description of what the bug is. Calling await recorder.closeAudioSession() triggers a Platform exception to be thrown. The exception is void com.dooboolab.fluttersound.RecorderInterface._stopRecorder()' on a null object reference. This happens even when I move the method call to dispose().

Expected behavior A clear and concise description of what you expected to happen. I expect calling await recorder.closeAudioSession() to simply clean up the audio resources, and not throw an exception.


Larpoux commented 4 years ago

Fixed in Pull Request #371 : closeRecorder is supposed to always work without throwing any exception. This verb was not correctly protected on Android.

chi-tea-72 commented 4 years ago

Thank you @Larpoux! When can we expect it to be merged to master?

Larpoux commented 4 years ago

Is that branch better ?

chi-tea-72 commented 4 years ago

Ok I'll try it out and let you know asap

chi-tea-72 commented 4 years ago

Hi @Larpoux, I just pulled in that branch and tested it, it doesn't throw an exception anymore, so looks good to me!

chi-tea-72 commented 4 years ago

Do you think it's better to call it in dispose() or before dispose happens. I tested it in both cases and it worked fine, but is there a preferred location to call it from, or does it not matter?

Larpoux commented 4 years ago

It does not matter. Probably during dispose() is convenient.

cristoj commented 4 years ago

Somebody kenows when will be this fix publicated in https://pub.dev/??? Thanks a lot.

Larpoux commented 4 years ago

I am currently working on FS 5.1.0 .

I hope to publish it later this week.

Teka-coder commented 2 months ago

The method 'closeAudioSession' isn't defined for the type 'FlutterSoundRecorder'. Try correcting the name to the name of an existing method, or defining a method named 'closeAudioSession'.dartundefined_method Type: InvalidType

Teka-coder commented 2 months ago

Because flutter_sound >=9.8.1 depends on flutter_sound_web 9.8.1 which depends on js ^0.7.1, flutter_sound >=9.8.1 requires js ^0.7.1. Because flutter_secure_storage_web 1.2.1 depends on js ^0.6.3 and no versions of flutter_secure_storage_web match >1.2.1 <2.0.0, flutter_secure_storage_web ^1.2.1 requires js ^0.6.3. Thus, flutter_sound >=9.8.1 is incompatible with flutter_secure_storage_web ^1.2.1. And because flutter_secure_storage 9.2.2 depends on flutter_secure_storage_web ^1.2.1 and no versions of flutter_secure_storage match >9.2.2 <10.0.0, flutter_sound >=9.8.1 is incompatible with flutter_secure_storage ^9.2.2. So, because customer_app depends on both flutter_secure_storage ^9.2.2 and flutter_sound ^9.8.1, version solving failed.

Larpoux commented 2 months ago

@Teka-coder : it seems that flutter_secure_storage_web 1.2.1 depends on js ^0.6.3, which is an old version of JS. I would not like to have to downgrade Flutter Sound to be compatible with this JS version, because others Flutter Sound users could complain that our plugin uses a too old JS version.

It would be better if flutter_secure_storage_web uses a more recent version of JS. What can we do ? What do you suggest ?

Larpoux commented 2 months ago

Flutter Secure Storage Web 2.0.0-beta-1 does not depend anymore on JS. Maybe you can consider using this version of Secure Storage Web ?