Tau: [BUG]: Unable to play audio file on Android

Created on 24 May 2021  Â·  5Comments  Â·  Source: Canardoux/tau

Flutter Sound Version :

  • FULL or LITE flavor ?

  • Important: Result of the command : flutter pub deps | grep flutter_sound
    flutter pub deps | grep flutter_sound
    |-- flutter_sound_lite 8.1.4
    | |-- flutter_sound_platform_interface 8.1.4
    | |-- flutter_sound_web 8.1.4
    | | |-- flutter_sound_platform_interface...


Severity

  • Result is not what expected

Platforms you faced the error

  • Android 10 on a OnePlus 6 physical device

Describe the bug
When attempting to play audio, the library throws an error and does not start playback. The same code works on iOS.

To Reproduce

try {
      await player.openAudioSession(
        focus: AudioFocus.requestFocusAndStopOthers,
        category: SessionCategory.playback,
        mode: SessionMode.modeSpokenAudio,
        withUI: true,
      );
      await player.setSubscriptionDuration(Duration(milliseconds: 50));
      streamSubscription = player.onProgress.listen((event) {
        playbackStream.add(event);
      });
      await player.startPlayer(
          fromURI: audioFilePath,
          whenFinished: () async {
            await stopPlayback();
            print("audio playback done");
          });
      status = PlayerStatus.playing;
      _statusStream.add(status);
    } catch (err, trace) {
      print(err);
      print(trace);
    }

Logs

I/flutter ( 5773): FS:---> openAudioSession
D/MediaBrowserCompat( 5773): Connecting to a MediaBrowserService.
I/AudioManager( 5773): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager( 5773): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager( 5773): In setSpeakerphoneOn(), on: true, calling application: com.example.voice_app
I/AudioManager( 5773): In setSpeakerphoneOn(), on: true, calling application: com.example.voice_app
I/AudioManager( 5773): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager( 5773): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager( 5773): In setMode(), mode: 0, calling application: com.example.voice_app
I/flutter ( 5773): FS:<--- openAudioSession
I/flutter ( 5773): FS:---> channelMethodCallHandler : openPlayerCompleted
I/flutter ( 5773): ---> openPlayerCompleted: true
I/flutter ( 5773): <--- openPlayerCompleted: true
I/flutter ( 5773): FS:<--- channelMethodCallHandler : openPlayerCompleted
I/flutter ( 5773): FS:---> setSubscriptionDuration
I/flutter ( 5773): FS:<---- setSubscriptionDuration
I/flutter ( 5773): FS:---> startPlayer
I/flutter ( 5773): FS:---> stop
E/MediaPlayerNative( 5773): stop called in state 0, mPlayer(0x0)
I/flutter ( 5773): FS:---> channelMethodCallHandler : stopPlayerCompleted
I/flutter ( 5773): ---> stopPlayerCompleted: true
I/flutter ( 5773): <--- stopPlayerCompleted: true
I/flutter ( 5773): FS:<--- channelMethodCallHandler : stopPlayerCompleted
V/MediaPlayer( 5773): resetDrmState: mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer( 5773): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter ( 5773): FS:<--- stop
I/flutter ( 5773): FS:---> _convert
I/flutter ( 5773): FS:---> needToConvert
I/flutter ( 5773): FS:<--- needToConvert
I/flutter ( 5773): FS:<--- _convert
E/FlutterSoundPlugin( 5773): startPlayer() exception
I/flutter ( 5773): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter ( 5773): FS:<--- channelMethodCallHandler : updatePlaybackState
I/flutter ( 5773): PlatformException(ERR_UNKNOWN, ERR_UNKNOWN, Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference, null)
I/flutter ( 5773): #0 StandardMethodCodec.decodeEnvelope
I/flutter ( 5773): #1 MethodChannel._invokeMethod
I/flutter ( 5773):
I/flutter ( 5773): #2 MethodChannelFlutterSoundPlayer.invokeMethod
I/flutter ( 5773):
I/flutter ( 5773): #3 FlutterSoundPlayer._startPlayer
I/flutter ( 5773):
I/flutter ( 5773): #4 FlutterSoundPlayer.startPlayer.
I/flutter ( 5773):
I/flutter ( 5773): #5 BasicLock.synchronized
I/flutter ( 5773):
I/flutter ( 5773): #6 FlutterSoundPlayer.startPlayer
I/flutter ( 5773):
I/flutter ( 5773): #7 AudioPlayerBloc.openPlayback
I/flutter ( 5773):


maybe bug Not yet handled

All 5 comments

    mode: SessionMode.modeSpokenAudio,
    withUI: true,

...

  await player.startPlayer(

Normally, you should call "startPlayerFromTrack()" when withUI is true.
Try to change to withUI: false, : the code is simpler without UI.

Also I suggest that you provide the codec parameter.
Of course you must be sure that your parameter fromURI: is correct.

    mode: SessionMode.modeSpokenAudio,
    withUI: true,

...

  await player.startPlayer(

Normally, you should call "startPlayerFromTrack()" when withUI is true.
Try to change to withUI: false, : the code is simpler without UI.

Also I suggest that you provide the codec parameter.
Of course you must be sure that your parameter fromURI: is correct.

All of this time, and setting withUI: false seems to have fixed it. WTF. Maybe there is still a bug here to be fixed internally in Tau, but my app seems to be working!

Yeah!!!!

I think :

  • Either Flutter Sound should be clear when not using "startPlayerFromTrack()" and withUI=true
  • Or accept correctely "startPlayer()" like it is done on iOS

The fix is simple. But actually I do not work anymore on Tau.
Someone can do a Pull Request ? (I always consider PR, because I want other developers on this project)

@mhstoller ,

How are you doing my friend ?
I added a few lines in the documentation for people trying to run flutter_sound inside a debugger :
Here

@mhstoller ,

How are you doing my friend ?
I added a few lines in the documentation for people trying to run flutter_sound inside a debugger :
Here

Awesome! Thank you for doing that. Hopefully others can contribute more now :)

Was this page helpful?
0 / 5 - 0 ratings