public void testSeekToAfterAttachedAsNextMediaPlayer() throws Throwable {
        IBasicMediaPlayer player = createWrappedPlayerInstance();
        IBasicMediaPlayer nextPlayer = null;
        Object args = getTestParams();
        // NOTE:
        // seekTo() call will be ignored if the player is attached as a next
        // player.
        try {
            // prepare
            transitStateToPrepared(player, args);
            nextPlayer = createNextPlayer(player, NextPlayerType.PREPARED);
            setUnwrappedtNextPlayer(player, nextPlayer);
            assertFalse(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
            // start
            player.start();
            assertTrue(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
            int seekPosition = nextPlayer.getDuration() / 2;
            SeekCompleteListenerObject seekComp = new SeekCompleteListenerObject();
            nextPlayer.setOnSeekCompleteListener(seekComp);
            nextPlayer.seekTo(seekPosition);
            if (!seekComp.await(DEFAULT_EVENT_WAIT_DURATION)) {
                fail();
            }
            // NOTE: valid position is returned
            assertEquals(seekPosition, nextPlayer.getCurrentPosition());
            Thread.sleep(SHORT_EVENT_WAIT_DURATION);
            assertTrue(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
            // wait for the next player started
            Thread.sleep(player.getDuration());
            // NOTE: StandardMediaPlayer fails on this assertion if using NuPlayer
            assertEquals(player.getDuration(), player.getCurrentPosition());
            assertFalse(player.isPlaying());
            assertTrue(nextPlayer.isPlaying());
            // NOTE: valid current position position is returned
            // XXX Galaxy S4 (SC-04E, Android 4.4.2) fails on this assertion
            assertLargerThanOrEqual(seekPosition,
                    nextPlayer.getCurrentPosition());
            // wait for the next player completion
            Thread.sleep(nextPlayer.getDuration() - seekPosition
                    + SHORT_EVENT_WAIT_DURATION);
            if (true) {
                Log.w("XXX",
                        "testSeekToAfterAttachedAsNextMediaPlayer() - WORKAROUND");
                // WTF! Android's native audio decoder gives very poor seek
                // accuracy!
                assertFalse(player.isPlaying());
                assertTrue(nextPlayer.isPlaying());
                // wait for the next player completion
                Thread.sleep(seekPosition);
            }
            assertEquals(nextPlayer.getDuration(),
                    nextPlayer.getCurrentPosition());
            assertFalse(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
        } finally {
            releaseQuietly(nextPlayer);
            releaseQuietly(player);
        }
    }
public void testSeekToAfterAttachedAsNextMediaPlayer() throws Throwable {
        IBasicMediaPlayer player = createWrappedPlayerInstance();
        IBasicMediaPlayer nextPlayer = null;
        Object args = getTestParams();
       
       
       
        try {
           
            transitStateToPrepared(player, args);
            nextPlayer = createNextPlayer(player, NextPlayerType.PREPARED);
            setUnwrappedtNextPlayer(player, nextPlayer);
            assertFalse(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
           
            player.start();
            assertTrue(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
            int seekPosition = nextPlayer.getDuration() / 2;
            SeekCompleteListenerObject seekComp = new SeekCompleteListenerObject();
            nextPlayer.setOnSeekCompleteListener(seekComp);
            nextPlayer.seekTo(seekPosition);
            if (!seekComp.await(DEFAULT_EVENT_WAIT_DURATION)) {
                fail();
            }
           
            assertEquals(seekPosition, nextPlayer.getCurrentPosition());
            Thread.sleep(SHORT_EVENT_WAIT_DURATION);
            assertTrue(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
           
            Thread.sleep(player.getDuration());
           
            assertEquals(player.getDuration(), player.getCurrentPosition());
            assertFalse(player.isPlaying());
            assertTrue(nextPlayer.isPlaying());
           
           
            assertLargerThanOrEqual(seekPosition,
                    nextPlayer.getCurrentPosition());
           
            Thread.sleep(nextPlayer.getDuration() - seekPosition
                    + SHORT_EVENT_WAIT_DURATION);
            if (true) {
                Log.w("XXX",
                        "testSeekToAfterAttachedAsNextMediaPlayer() - WORKAROUND");
               
               
                assertFalse(player.isPlaying());
                assertTrue(nextPlayer.isPlaying());
               
                Thread.sleep(seekPosition);
            }
            assertEquals(nextPlayer.getDuration(),
                    nextPlayer.getCurrentPosition());
            assertFalse(player.isPlaying());
            assertFalse(nextPlayer.isPlaying());
        } finally {
            releaseQuietly(nextPlayer);
            releaseQuietly(player);
        }
    }
public void testseektoafterattachedasnextmediaplayer() throws throwable { ibasicmediaplayer player = createwrappedplayerinstance(); ibasicmediaplayer nextplayer = null; object args = gettestparams(); try { transitstatetoprepared(player, args); nextplayer = createnextplayer(player, nextplayertype.prepared); setunwrappedtnextplayer(player, nextplayer); assertfalse(player.isplaying()); assertfalse(nextplayer.isplaying()); player.start(); asserttrue(player.isplaying()); assertfalse(nextplayer.isplaying()); int seekposition = nextplayer.getduration() / 2; seekcompletelistenerobject seekcomp = new seekcompletelistenerobject(); nextplayer.setonseekcompletelistener(seekcomp); nextplayer.seekto(seekposition); if (!seekcomp.await(default_event_wait_duration)) { fail(); } assertequals(seekposition, nextplayer.getcurrentposition()); thread.sleep(short_event_wait_duration); asserttrue(player.isplaying()); assertfalse(nextplayer.isplaying()); thread.sleep(player.getduration()); assertequals(player.getduration(), player.getcurrentposition()); assertfalse(player.isplaying()); asserttrue(nextplayer.isplaying()); assertlargerthanorequal(seekposition, nextplayer.getcurrentposition()); thread.sleep(nextplayer.getduration() - seekposition + short_event_wait_duration); if (true) { log.w("xxx", "testseektoafterattachedasnextmediaplayer() - workaround"); assertfalse(player.isplaying()); asserttrue(nextplayer.isplaying()); thread.sleep(seekposition); } assertequals(nextplayer.getduration(), nextplayer.getcurrentposition()); assertfalse(player.isplaying()); assertfalse(nextplayer.isplaying()); } finally { releasequietly(nextplayer); releasequietly(player); } }