/** * Workaround to fix some devices (nexus 7 2013 in particular) from natively crashing the mediaplayer * by starting the mediaplayer before seeking it. */ private void initialSeekWorkaround(Either<Surface, SurfaceHolder> surface, final long initialPlayPositionInMillis) throws IllegalStateException { listenersHolder.getBufferStateListeners().onBufferStarted(); initialisePlaybackForSeeking(surface); delayedActionExecutor.performAfterDelay(new DelayedActionExecutor.Action() { @Override public void perform() { seekWithIntentToPlay(initialPlayPositionInMillis); } }, INITIAL_PLAY_SEEK_DELAY_IN_MILLIS); }
@Test public void givenMultipleQueuedActions_whenClearingActions_thenRemovesAllActions() { delayedActionExecutor = new DelayedActionExecutor(nonExecutingHandler, runnables); delayedActionExecutor.performAfterDelay(action, ANY_DELAY_IN_MILLIS); delayedActionExecutor.performAfterDelay(secondaryAction, ANY_DELAY_IN_MILLIS); delayedActionExecutor.clearAllActions(); assertThat(runnables).isEmpty(); verify(nonExecutingHandler, times(2)).removeCallbacks(any(Runnable.class)); }
@Test public void givenPositionThatDiffersFromPlayheadPosition_whenStartingPlayAtVideoPosition_thenSeeksToVideoPosition() { long differentPositionInMillis = givenPositionThatDiffersFromPlayheadPosition(); player.playAt(differentPositionInMillis); ArgumentCaptor<DelayedActionExecutor.Action> argumentCaptor = ArgumentCaptor.forClass(DelayedActionExecutor.Action.class); verify(delayedActionExecutor).performAfterDelay(argumentCaptor.capture(), eq(DELAY_MILLIS)); argumentCaptor.getValue().perform(); verify(mediaPlayer).seekTo(differentPositionInMillis); }
@Test public void whenPerformingActionAfterDelay_thenPerformsAction() { delayedActionExecutor = new DelayedActionExecutor(immediatelyExecutingHandler, runnables); delayedActionExecutor.performAfterDelay(action, ANY_DELAY_IN_MILLIS); verify(action).perform(); }
@Test public void whenPerformingActionAfterDelay_thenRemovesActionFromMap() { delayedActionExecutor = new DelayedActionExecutor(immediatelyExecutingHandler, runnables); delayedActionExecutor.performAfterDelay(action, ANY_DELAY_IN_MILLIS); assertThat(runnables).isEmpty(); }
@Test public void whenActionIsNotPerformedYet_thenMapContainsAction() { delayedActionExecutor = new DelayedActionExecutor(nonExecutingHandler, runnables); delayedActionExecutor.performAfterDelay(action, ANY_DELAY_IN_MILLIS); assertThat(runnables).hasSize(1); }