SRGSSR / srgmediaplayer-apple

An advanced media player library, simple and reliable
MIT License
158 stars 33 forks source link

The player starts to play if the stop method is called when the playback state is still idle or preparing #26

Closed fredhdroz closed 7 years ago

fredhdroz commented 7 years ago

Issue overview

Description of the problem

When we play a media and call the "stop" method while the player is still idle or preparing, the player starts to play anyway

CALL STOP WHILE STILL IDLE AFTER PLAY METHOD IS CALLED

2017-07-27 11:20:41.406371+0200  [4698:1757814] WILL PLAY - PLAYBACKSTATE = 1
2017-07-27 11:20:41.409107+0200  [4698:1757814] DID PLAY - PLAYBACKSTATE =  1
2017-07-27 11:20:41.441540+0200  [4698:1757814] ...
2017-07-27 11:20:42.723282+0200  [4698:1757814] WILL ASK FOR STOP - PLAYBACKSTATE =  1
2017-07-27 11:20:42.723391+0200  [4698:1757814] DID ASK FOR STOP
2017-07-27 11:20:44.635106+0200  [4698:1757814] [Controller] Playing
2017-07-27 11:20:44.635328+0200  [4698:1757814] self.mediaPlayerController.playbackState 2
2017-07-27 11:20:44.639759+0200  [4698:1757814] [Controller] Playback state did change to preparing with info {
    SRGMediaPlayerPlaybackStateKey = 2;
    SRGMediaPlayerPreviousPlaybackStateKey = 1;
    SRGMediaPlayerSelectionKey = 0;
}
2017-07-27 11:20:48.002316+0200  [4698:1757814] self.mediaPlayerController.playbackState 3
2017-07-27 11:20:48.014082+0200  [4698:1757814] [Controller] Playback state did change to playing with info {
    SRGMediaPlayerPlaybackStateKey = 3;
    SRGMediaPlayerPreviousPlaybackStateKey = 2;
    SRGMediaPlayerSelectionKey = 0;
}

CALL STOP WHEN PREPARING

2017-07-27 11:22:35.166238+0200  [4702:1758624] WILL PLAY - PLAYBACKSTATE =  1
2017-07-27 11:22:35.169096+0200  [4702:1758624] DID PLAY - PLAYBACKSTATE =  1
2017-07-27 11:22:38.416480+0200  [4702:1758624] [Controller] Playing 
2017-07-27 11:22:38.416945+0200  [4702:1758624] self.mediaPlayerController.playbackState 2
2017-07-27 11:22:38.417005+0200  [4702:1758624] WILL ASK FOR STOP - PLAYBACKSTATE =  2
2017-07-27 11:22:38.417188+0200  [4702:1758624] self.mediaPlayerController.playbackState 1
2017-07-27 11:22:38.425274+0200  [4702:1758624] [Controller] Playback state did change to idle with info {
    SRGMediaPlayerPlaybackStateKey = 1;
    SRGMediaPlayerPreviousPlaybackStateKey = 2;
    SRGMediaPlayerSelectionKey = 0;
}
2017-07-27 11:22:38.425337+0200  [4702:1758624] DID ASK FOR STOP
2017-07-27 11:22:38.429552+0200  [4702:1758624] [Controller] Playback state did change to preparing with info {
    SRGMediaPlayerPlaybackStateKey = 2;
    SRGMediaPlayerPreviousPlaybackStateKey = 1;
    SRGMediaPlayerSelectionKey = 0;
}
2017-07-27 11:22:41.804323+0200  [4702:1758624] self.mediaPlayerController.playbackState 3
2017-07-27 11:22:41.807534+0200  [4702:1758624] [Controller] Playback state did change to playing with info {
    SRGMediaPlayerPlaybackStateKey = 3;
    SRGMediaPlayerPreviousPlaybackStateKey = 1;
    SRGMediaPlayerSelectionKey = 0;
}

Environment information

Reproducibility

Code sample

- (void)playMedia
{
    NSLog(@" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WILL PLAY  - PLAYBACKSTATE = %tu", self.mediaPlayerController.playbackState);
    [self.mediaPlayerController playURL:[NSURL URLWithString:@"..."]];
    NSLog(@" !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DID PLAY  - PLAYBACKSTATE = %tu", self.mediaPlayerController.playbackState);
}

- (IBAction)stopPlayer:(id)sender
{
    NSLog(@"WILL ASK FOR STOP - PLAYBACKSTATE =  %tu", self.mediaPlayerController.playbackState);
    [self.mediaPlayerController stop];
    NSLog(@"DID ASK FOR STOP");
}

- (void)playbackStateDidChange:(NSNotification *)notification
{
    if (self.mediaPlayerController.playbackState == SRGMediaPlayerPlaybackStatePreparing) {
        [self stopPlayer:nil];
    }
}

Steps to reproduce

  1. Setup Network link conditionner to High latency or slow network (easier to reproduce)
  2. Start playing a media
  3. Immediately call stop when player is still preparing or idle
  4. Wait a little while... the media will start to play