@Override public void stop() { synchronized (actionSynchronizer) { Thread thread = playingThread.get(); if (thread != null) { log.debug("Requesting stop for track {}", audioTrack.getIdentifier()); queuedStop.compareAndSet(false, true); thread.interrupt(); } else { log.debug("Tried to stop track {} which is not playing.", audioTrack.getIdentifier()); } } }
private void interruptForSeek() { boolean interrupted = false; synchronized (actionSynchronizer) { if (interruptibleForSeek) { interruptibleForSeek = false; Thread thread = playingThread.get(); if (thread != null) { thread.interrupt(); interrupted = true; } } } if (interrupted) { log.debug("Interrupting playing thread to perform a seek {}", audioTrack.getIdentifier()); } else { log.debug("Seeking on track {} while not in playback loop.", audioTrack.getIdentifier()); } }
audioTrack.process(this); log.debug("Playing track {} finished or was stopped.", audioTrack.getIdentifier()); } catch (Throwable e) { log.debug("Track {} was interrupted outside of execution loop.", audioTrack.getIdentifier()); } else { frameBuffer.setTerminateOnEmpty(); ExceptionTools.log(log, exception, "playback of " + audioTrack.getIdentifier()); log.warn("Tried to start an already playing track {}", audioTrack.getIdentifier());
/** * Performs a seek if it scheduled. * @param seekExecutor Callback for performing a seek on the track * @return True if a seek was performed */ private SeekResult checkPendingSeek(SeekExecutor seekExecutor) { if (!audioTrack.isSeekable()) { return SeekResult.NO_SEEK; } long seekPosition; synchronized (actionSynchronizer) { seekPosition = queuedSeek.get(); if (seekPosition == -1) { return SeekResult.NO_SEEK; } log.debug("Track {} interrupted for seeking to {}.", audioTrack.getIdentifier(), seekPosition); applySeekState(seekPosition); } if (seekExecutor != null) { try { seekExecutor.performSeek(seekPosition); } catch (Exception e) { throw ExceptionTools.wrapUnfriendlyExceptions("Something went wrong when seeking to a position.", FAULT, e); } return SeekResult.INTERNAL_SEEK; } else { return SeekResult.EXTERNAL_SEEK; } }