Canardoux / flutter_sound

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

[BUG] Android onProgress stream emits duplicate events #617

Open mhstoller opened 3 years ago

mhstoller commented 3 years ago

Flutter Sound Version :


Severity


Platforms you faced the error


Describe the bug When listening to an audio file over and over, the onProgress stream emits playback positions from previous sessions

To Reproduce Steps to reproduce the behavior:

  1. Open an audio session
  2. Set a subscription duration using setSubscriptionDuration
  3. Listen to the onProgress stream
  4. startPlayer() and let audio play
  5. Close audio session
  6. Open a new audio session
  7. startPlayer()
  8. The onProgress stream will now emit events from this current audio session, as well as the last one

This will continue for each time you start the playback, so if you play it 4 times in a row you would end up with 4 stream events being sent for each progress event (3 of those events will be incorrect each time)

Expected behavior Only emit events from the current audio session


Code sample

  FlutterSoundPlayer player = FlutterSoundPlayer();
  StreamSubscription<PlaybackDisposition> streamSubscription;

//called when starting playback
await player.openAudioSession(
        focus: AudioFocus.requestFocusAndStopOthers,
        category: SessionCategory.playback,
        mode: SessionMode.modeSpokenAudio,
        withUI: true,
      );
      await player.setSubscriptionDuration(Duration(milliseconds: 100));
      streamSubscription = player.onProgress.listen((event) {
        print("Event: ${event.position}");
      });
      await player.startPlayer(
          fromURI: audioFile,
          whenFinished: () async {
            await stopPlayback();
          });

//called when playback is completed
  Future stopPlayback() async {
    await streamSubscription.cancel();
    await player.stopPlayer();
    await player.closeAudioSession();
    return;
  }

Logs

First play (normal)

I/flutter (19653): FS:---> openAudioSession
D/MediaBrowserCompat(19653): Connecting to a MediaBrowserService.
I/AudioManager(19653): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager(19653): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager(19653): In setSpeakerphoneOn(), on: true, calling application: com.example.voice_app
I/AudioManager(19653): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager(19653): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager(19653): In setMode(), mode: 0, calling application: com.example.voice_app
I/flutter (19653): FS:<--- openAudioSession
I/flutter (19653): FS:---> channelMethodCallHandler : openAudioSessionCompleted
I/flutter (19653): FS:<--- channelMethodCallHandler : openAudioSessionCompleted
I/flutter (19653): FS:---> setSubscriptionDuration
I/flutter (19653): FS:<---- setSubscriptionDuration
I/flutter (19653): FS:---> startPlayer
I/flutter (19653): FS:---> stop
E/MediaPlayerNative(19653): stop called in state 1, mPlayer(0x0)
E/MediaPlayerNative(19653): error (-38, 0)
I/flutter (19653): FS:<--- stop
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> _convert
I/flutter (19653): FS:---> needToConvert
I/flutter (19653): FS:<--- needToConvert
I/flutter (19653): FS:<--- _convert
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:<--- startPlayer
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
D/FlautoPlayer(19653): mediaPlayer prepared and started
I/flutter (19653): FS:---> channelMethodCallHandler : startPlayerCompleted
I/flutter (19653): FS:<--- channelMethodCallHandler : startPlayerCompleted
I/flutter (19653): Event: 0:00:00.000000
I/flutter (19653): Event: 0:00:00.020000
I/flutter (19653): Event: 0:00:00.242000
I/flutter (19653): Event: 0:00:00.343000
I/flutter (19653): Event: 0:00:00.443000
I/flutter (19653): Event: 0:00:00.544000
I/flutter (19653): Event: 0:00:00.644000
I/flutter (19653): Event: 0:00:00.745000
I/flutter (19653): Event: 0:00:00.845000
I/flutter (19653): Event: 0:00:00.946000
I/flutter (19653): Event: 0:00:01.048000
I/flutter (19653): Event: 0:00:01.149000
I/flutter (19653): Event: 0:00:01.250000
I/flutter (19653): Event: 0:00:01.352000
I/flutter (19653): Event: 0:00:01.453000
I/flutter (19653): Event: 0:00:01.553000
I/flutter (19653): Event: 0:00:01.654000
I/flutter (19653): Event: 0:00:01.755000
I/flutter (19653): Event: 0:00:01.857000
I/flutter (19653): Event: 0:00:01.958000
I/flutter (19653): Event: 0:00:02.059000
I/flutter (19653): Event: 0:00:02.161000
I/flutter (19653): Event: 0:00:02.261000
I/flutter (19653): Event: 0:00:02.363000
I/flutter (19653): Event: 0:00:02.464000
I/flutter (19653): Event: 0:00:02.564000
I/flutter (19653): Event: 0:00:02.665000
I/flutter (19653): Event: 0:00:02.767000
I/flutter (19653): Event: 0:00:02.866000
I/flutter (19653): Event: 0:00:02.968000
I/flutter (19653): Event: 0:00:03.069000
I/flutter (19653): Event: 0:00:03.170000
I/flutter (19653): Event: 0:00:03.271000
I/flutter (19653): Event: 0:00:03.372000
I/flutter (19653): Event: 0:00:03.474000
I/flutter (19653): Event: 0:00:03.577000
I/flutter (19653): Event: 0:00:03.676000
I/flutter (19653): Event: 0:00:03.778000
I/flutter (19653): Event: 0:00:03.879000
I/flutter (19653): Event: 0:00:03.981000
I/flutter (19653): Event: 0:00:04.083000
I/flutter (19653): Event: 0:00:04.183000
I/flutter (19653): Event: 0:00:04.283000
I/flutter (19653): Event: 0:00:04.385000
I/flutter (19653): Event: 0:00:04.486000
I/flutter (19653): Event: 0:00:04.588000
I/flutter (19653): Event: 0:00:04.660000
D/FlautoPlayer(19653): Playback completed.
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> channelMethodCallHandler : audioPlayerFinishedPlaying
I/flutter (19653): FS:---> audioPlayerFinished
I/flutter (19653): FS:---> stopPlayer
I/flutter (19653): FS:---> stop
I/flutter (19653): FS:<--- audioPlayerFinished
I/flutter (19653): FS:<--- channelMethodCallHandler : audioPlayerFinishedPlaying
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
I/flutter (19653): FS:<--- stop
I/flutter (19653): FS:<--- stopPlayer
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> closeAudioSession
I/flutter (19653): FS:---> stop
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
I/flutter (19653): FS:<--- stop
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- closeAudioSession

Second play (onProgress emits "0:00:04.660000" as the playback position in between each real stream event):

I/flutter (19653): FS:---> openAudioSession
D/MediaBrowserCompat(19653): Connecting to a MediaBrowserService.
I/AudioManager(19653): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager(19653): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager(19653): In setSpeakerphoneOn(), on: true, calling application: com.example.voice_app
I/AudioManager(19653): In setBluetoothScoOn(), on: false, calling application: com.example.voice_app
I/AudioManager(19653): In stopBluetoothSco(), calling application: com.example.voice_app
I/AudioManager(19653): In setMode(), mode: 0, calling application: com.example.voice_app
I/flutter (19653): FS:<--- openAudioSession
I/flutter (19653): FS:---> channelMethodCallHandler : openAudioSessionCompleted
I/flutter (19653): FS:<--- channelMethodCallHandler : openAudioSessionCompleted
I/flutter (19653): FS:---> setSubscriptionDuration
I/flutter (19653): FS:<---- setSubscriptionDuration
I/flutter (19653): FS:---> startPlayer
I/flutter (19653): FS:---> stop
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
I/flutter (19653): FS:<--- stop
I/flutter (19653): FS:---> _convert
I/flutter (19653): FS:---> needToConvert
I/flutter (19653): FS:<--- needToConvert
I/flutter (19653): FS:<--- _convert
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:<--- startPlayer
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
D/FlautoPlayer(19653): mediaPlayer prepared and started
I/flutter (19653): FS:---> channelMethodCallHandler : startPlayerCompleted
I/flutter (19653): FS:<--- channelMethodCallHandler : startPlayerCompleted
I/flutter (19653): Event: 0:00:00.000000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.000000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.020000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.020000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.227000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.328000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted
I/flutter (19653): Event: 0:00:00.429000
I/flutter (19653): Event: 0:00:04.660000 <--- should not be emitted..etc.
I/flutter (19653): Event: 0:00:00.531000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:00.632000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:00.732000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:00.834000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:00.934000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.033000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.136000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.235000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.336000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.436000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.536000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.636000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.735000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.837000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:01.938000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.038000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.140000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.239000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.340000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.441000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.543000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.644000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.745000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.845000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:02.945000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.046000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.147000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.249000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.350000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.450000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.552000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.654000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.754000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.855000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:03.959000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.060000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.161000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.261000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.361000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.462000
I/flutter (19653): Event: 0:00:04.660000
I/flutter (19653): Event: 0:00:04.563000
I/flutter (19653): Event: 0:00:04.660000
I/chatty  (19653): uid=10306(com.example.voice_app) 1.ui identical 3 lines
I/flutter (19653): Event: 0:00:04.660000
D/FlautoPlayer(19653): Playback completed.
I/flutter (19653): FS:---> channelMethodCallHandler : audioPlayerFinishedPlaying
I/flutter (19653): FS:---> audioPlayerFinished
I/flutter (19653): FS:---> stopPlayer
I/flutter (19653): FS:---> stop
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
I/flutter (19653): FS:<--- audioPlayerFinished
I/flutter (19653): FS:<--- channelMethodCallHandler : audioPlayerFinishedPlaying
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- stop
I/flutter (19653): FS:<--- stopPlayer
I/flutter (19653): FS:---> closeAudioSession
I/flutter (19653): FS:---> stop
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
E/MediaPlayerNative(19653): stop called in state 0, mPlayer(0x0)
I/flutter (19653): FS:<--- stop
V/MediaPlayer(19653): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(19653): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (19653): FS:---> channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- channelMethodCallHandler : updatePlaybackState
I/flutter (19653): FS:<--- closeAudioSession
Larpoux commented 3 years ago

Thank your for your PR (Problem Report). This bug is really bad, and must be fixed soon.

mhstoller commented 3 years ago

I'm no longer able to reproduce this on flutter_sound_lite 8.1.4, closing for now and will re-open if it happens again.

Larpoux commented 3 years ago

I am re-opening this issue. Nothing has been fixed in this area, and I guess that this bug is still there.

github-actions[bot] commented 10 months ago

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.