public synchronized void start() { // Clear the mission introduction when the mission is started (not resumed after a pause) if (stopWatch.missionTimeInNanos() == 0) { missionLog.clear(); missionActivity.clearMissionLog(); } if (mediaPlayerList.size() <= playerIndex) { init(); } stopWatch.start(); stopped = false; if (paused) { paused = false; // Even when a running sound was paused, you have to update the // startTime for the next file startTime += System.nanoTime() - timeWhenPaused; if (activeMediaPlayer == null) { mediaPlayerBackgroundSounds.start(); } else { activeMediaPlayer.start(); } if (activeMediaPlayer == null || activeMediaPlayer.isLooping()) { postAtTime( mPlayNextAudioTask, startTime + mediaPlayerList.get(playerIndex).getStartTimeNanos()); } return; } startTime = System.nanoTime(); playNextAudio(); }
@Override public synchronized void stop() { super.stop(); missionActivity.toggleOff(); mediaPlayerBackgroundSounds.stop(); stopWatch.stop(); timerHandler.removeCallbacks(mPlayNextAudioTask); }
@Override public synchronized void pause() { super.pause(); stopWatch.pause(); mediaPlayerBackgroundSounds.pause(); missionActivity.toggleOff(); timeWhenPaused = System.nanoTime(); timerHandler.removeCallbacks(mPlayNextAudioTask); }
private void planNextAudioTask() { playerIndex++; if (mediaPlayerList.size() > playerIndex) { long nextTime = startTime + mediaPlayerList.get(playerIndex).getStartTimeNanos(); if (activeMediaPlayer == null && nextTime > System.nanoTime()) { mediaPlayerBackgroundSounds.start(); } postAtTime(mPlayNextAudioTask, nextTime); } else { stop(); } }
public void run() { mediaPlayerBackgroundSounds.pause(); playNextAudio(); }