Skip to content

[BUG] player.onStopped is never called. Disposition position is never equal to duration either #29

Closed

Description

@SaadArdati

Sounds Version :

^1.0.0-beta.7


Severity

Major


Platforms you faced the error

Android Emulator


Given the following code:

    player = SoundPlayer.withShadeUI(
        playInBackground: true, canPause: true, canSkipBackward: true, canSkipForward: true);

    player.onStarted = ({wasUser}) {
      _playerEventController.add(PlayerEventPlay(activeTrack));
    };
    player.onResumed = ({wasUser}) {
      _playerEventController.add(PlayerEventResumed());
    };
    player.onPaused = ({wasUser}) {
      _playerEventController.add(PlayerEventPaused());
    };
    player.onStopped = ({wasUser}) {
      player.dispositionStream().last.then((disposition) {
        if (disposition.duration == disposition.position) {
          _playerEventController.add(PlayerEventStoppedNaturally());
        } else {
          _playerEventController.add(PlayerEventStopped());
        }
      });
    };
    player.onSkipBackward = () => _playerEventController.add(PlayerEventPlayPrevious());
    player.onSkipForward = () => _playerEventController.add(PlayerEventPlayNext());

and

  @override
  Stream<int> positionStream() => player.dispositionStream();

onStopped is never called when the track ends. It fires when the player is stopped manually, but never naturally.

There is not a single event that fires when the track ends naturally.

This is my log when a track reaches its end:

I/flutter (26537): PositionCubit Change { currentState: 162497, nextState: 162502 }
I/flutter (26537): �[38;5;249m13 21:18:52.711 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): PositionCubit Change { currentState: 162502, nextState: 162506 }
I/flutter (26537): �[38;5;249m13 21:18:52.717 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): PositionCubit Change { currentState: 162506, nextState: 162507 }
I/flutter (26537): �[38;5;249m13 21:18:52.732 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): PositionCubit Change { currentState: 162507, nextState: 162512 }
I/flutter (26537): �[38;5;249m13 21:18:52.734 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): PositionCubit Change { currentState: 162512, nextState: 162514 }
I/flutter (26537): �[38;5;249m13 21:18:52.738 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): PositionCubit Change { currentState: 162514, nextState: 162524 }
D/SoundPlayer(26537): Plays completed.
I/flutter (26537): �[38;5;249m13 21:18:52.761 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback audioPlayerFinishedPlaying�[0m
I/flutter (26537): PositionCubit Change { currentState: 162524, nextState: 162664 }
V/MediaPlayer(26537): resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false
V/MediaPlayer(26537): cleanDrmObj: mDrmObj=null mDrmSessionId=null
I/flutter (26537): �[38;5;249m13 21:18:52.834 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.836 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.849 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.859 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.865 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.871 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.875 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.884 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m
I/flutter (26537): �[38;5;249m13 21:18:52.890 Debug player_base_plugin.dart : PlayerBasePlugin.onMethodCallback : 194 ::: OS callback updateProgress�[0m

You can immediately see that my position that's listening to the disposition listener is NOT ending with position = duration; it cuts short.
Print statements also never print in the onStopped event.
There is no way to tell if a track ended naturally.

isPlayer returns false but there's no event to allow us to check if it's done or not because disposition stream ends before isPlayer can return false.

Activity

  1. changed the title [-][BUG] player.onStopped is never called.[/-] [+][BUG] player.onStopped is never called. Disposition position is never equal to duration either[/+] on Aug 13, 2020
  2. bsutton commented on Aug 16, 2020

    @bsutton
    Owner

    So this look like a bug.
    The disposition stream is meant to guarentee a final event that has disposition.duration == disposition.position.

    will investigate.

  3. relf108 commented on Aug 18, 2020

    @relf108
    Collaborator

    I managed to reproduce this but it is not actually a bug. The issue you are having is that you are attempting to listen to the disposition stream after it's last event has fired. Due to dispositions streams being a type of broadcast stream you will only be able to see events as they are fired. You need to set up your listener before the onStopped method is called in order to access your duration and position. I'll be updating the wiki to reflect this.
    Here's some doco on broadcast streams that will do a better job explaining them than me.

  4. SaadArdati commented on Aug 18, 2020

    @SaadArdati
    Author

    @relf108 The doc is quite large, I couldn't find where you updated it, if you could paste the relevant link, that would be much appreciated.
    As far as I'm aware about streams, the time of listener registeration does nothing. And even if it did, I don't have much leeway in the matter. The player stays active for the entire lifecycle of the app and the listener is never stopped at any point.

    Did you mean to say we should be using dispositionStream.last to get the last value when the onStopped method is fired?

  5. bsutton commented on Aug 18, 2020

    @bsutton
    Owner
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions