Пример #1
0
        /// <summary>
        /// Executes an audio track with the given player and volume. </summary>
        /// <param name="listener"> A listener for track state events </param>
        /// <param name="track"> The audio track to execute </param>
        /// <param name="configuration"> The audio configuration to use for executing </param>
        /// <param name="volumeLevel"> The mutable volume level to use </param>
        //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
        //ORIGINAL LINE: public void executeTrack(final TrackStateListener listener, InternalAudioTrack track, AudioConfiguration configuration, AtomicInteger volumeLevel)
        public virtual void executeTrack(TrackStateListener listener, InternalAudioTrack track, AudioConfiguration configuration, AtomicInteger volumeLevel)
        {
            //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
            //ORIGINAL LINE: final AudioTrackExecutor executor = createExecutorForTrack(track, configuration, volumeLevel);
            AudioTrackExecutor executor = createExecutorForTrack(track, configuration, volumeLevel);

            track.assignExecutor(executor, true);

            trackPlaybackExecutorService.execute(() => executor.execute(listener));
        }
        public void execute(TrackStateListener listener)
        {
            InterruptedException interrupt = null;

            if (java.lang.Thread.interrupted())
            {
                log.LogDebug("Cleared a stray interrupt.");
            }

            if (playingThread.compareAndSet(null, System.Threading.Thread.CurrentThread))
            {
                log.LogDebug("Starting to play track {} locally with listener {}", audioTrack.Info.identifier, listener);

                state.set(AudioTrackState.LOADING);

                try
                {
                    audioTrack.process(this);

                    log.LogDebug("Playing track {} finished or was stopped.", audioTrack.Identifier);
                }
                catch (System.Exception e)
                {
                    // Temporarily clear the interrupted status so it would not disrupt listener methods.
                    interrupt = findInterrupt(e);

                    if (interrupt != null && checkStopped())
                    {
                        log.LogDebug("Track {} was interrupted outside of execution loop.", audioTrack.Identifier);
                    }
                    else
                    {
                        frameBuffer.setTerminateOnEmpty();

                        FriendlyException exception = ExceptionTools.wrapUnfriendlyExceptions("Something broke when playing the track.", FAULT, e);
                        ExceptionTools.log(log, exception, "playback of " + audioTrack.Identifier);

                        trackException = exception;
                        listener.onTrackException(audioTrack, exception);

                        ExceptionTools.rethrowErrors(e);
                    }
                }
                finally
                {
                    lock (actionSynchronizer)
                    {
                        interrupt = interrupt != null ? interrupt : findInterrupt(null);

                        playingThread.compareAndSet(System.Threading.Thread.CurrentThread, null);

                        markerTracker.trigger(ENDED);
                        state.set(AudioTrackState.FINISHED);
                    }

                    if (interrupt != null)
                    {
                        System.Threading.Thread.CurrentThread.Interrupt();
                    }
                }
            }
            else
            {
                log.LogWarning("Tried to start an already playing track {}", audioTrack.Identifier);
            }
        }