示例#1
0
        /// <summary>
        /// Creates and initializes a new instance.
        /// </summary>
        /// <param name="controller">Reference to controller object.</param>
        public static PlaybackSession Create(Controller controller)
        {
            IInputSource inputSource = controller.PlaybackProcessor.GetAndClearNextInputSource();

            if (inputSource == null)
            {
                return(null);
            }
            BassStream      stream          = inputSource.OutputStream;
            PlaybackSession playbackSession = new PlaybackSession(controller, stream.Channels, stream.SampleRate, stream.IsPassThrough);

            playbackSession.Initialize(inputSource);
            return(playbackSession);
        }
示例#2
0
        public void Dispose()
        {
            lock (_syncObj)
                if (_nextInputSource != null)
                {
                    _nextInputSource.Dispose();
                    _nextInputSource = null;
                }
            PlaybackSession playbackSession = _playbackSession;

            if (playbackSession != null)
            {
                playbackSession.Dispose();
            }
        }
示例#3
0
        public void Stop()
        {
            if (_internalState == InternalPlaybackState.Playing || _internalState == InternalPlaybackState.Paused)
            {
                PlaybackSession session = _playbackSession;
                _playbackSession = null;
                if (session != null)
                {
                    session.End(false);
                    session.Dispose();
                }

                _internalState = InternalPlaybackState.Stopped;
            }
        }
示例#4
0
        /// <summary>
        /// Notifies this instance that a new input source has become available.
        /// </summary>
        /// <remarks>
        /// This method might block the calling thread as long as the switching to the new input source lasts in some cases.
        /// See the notes for <see cref="MoveToNextInputSource_Sync()"/>.
        /// </remarks>
        protected void NextInputSourceAvailable_Sync()
        {
            PlaybackSession session = _playbackSession;

            if (session != null && session.IsAwaitingNextInputSource)
            {
                // In this case, the session will automatically switch to the new item
                return;
            }
            if (session == null || session.State == SessionState.Ended)
            {
                // We might come here if the session ran out of samples before a new input source arrived.
                // In that case, we must continue "by hand".
                MoveToNextInputSource_Sync();
            }
        }
 /// <summary>
 /// Creates and initializes a new instance.
 /// </summary>
 /// <param name="controller">Reference to controller object.</param>
 public static PlaybackSession Create(Controller controller)
 {
   IInputSource inputSource = controller.PlaybackProcessor.GetAndClearNextInputSource();
   if (inputSource == null)
     return null;
   BassStream stream = inputSource.OutputStream;
   PlaybackSession playbackSession = new PlaybackSession(controller, stream.Channels, stream.SampleRate, stream.IsPassThrough);
   playbackSession.Initialize(inputSource);
   return playbackSession;
 }
示例#6
0
        /// <summary>
        /// Moves to the next available input source.
        /// </summary>
        /// <remarks>
        /// This method blocks the calling thread as long as the switching to the new input source lasts. This includes
        /// the crossfading duration (if crossfading is done) or the fading out (if no crossfading is done).
        /// </remarks>
        protected void MoveToNextInputSource_Sync()
        {
            // TODO: Insert gap between tracks if we are in playback mode Normal
            IInputSource inputSource = PeekNextInputSource();

            if (_playbackSession != null)
            {
                BassCDTrackInputSource bcdtisNew          = inputSource as BassCDTrackInputSource;
                IInputSource           currentInputSource = _playbackSession.CurrentInputSource;
                BassCDTrackInputSource bcdtisOld          = currentInputSource as BassCDTrackInputSource;
                if (bcdtisOld != null && bcdtisNew != null)
                {
                    // Special treatment for CD drives: If the new input source is from the same audio CD drive, we must take the stream over
                    if (bcdtisOld.SwitchTo(bcdtisNew))
                    {
                        _playbackSession.IsAwaitingNextInputSource = false;
                        ClearNextInputSource();
                        return;
                    }
                }
                // TODO: Trigger crossfading if CF is configured
                _playbackSession.End(_internalState == InternalPlaybackState.Playing); // Only wait for fade out when we are playing
            }

            _internalState = InternalPlaybackState.Playing;
            if (inputSource == null)
            {
                Log.Debug("No more input sources available.");
            }
            else
            {
                Log.Debug("Playing next input source '{0}'", inputSource);
            }
            if (_playbackSession != null)
            {
                if (_playbackSession.InitializeWithNewInputSource(inputSource))
                {
                    _playbackSession.Play();
                    ClearNextInputSource();
                    return;
                }
                _playbackSession.Dispose();
                _playbackSession = null;
            }

            if (inputSource == null)
            {
                Ended();
                return;
            }

            _playbackSession = PlaybackSession.Create(_controller);
            if (_playbackSession == null)
            {
                _internalState = InternalPlaybackState.Stopped;
                return;
            }
            _playbackSession.Play();

            _internalState = InternalPlaybackState.Playing;
            _controller.StateReady();
        }
    public void Stop()
    {
      if (_internalState == InternalPlaybackState.Playing || _internalState == InternalPlaybackState.Paused)
      {
        PlaybackSession session = _playbackSession;
        _playbackSession = null;
        if (session != null)
        {
          session.End(false);
          session.Dispose();
        }

        _internalState = InternalPlaybackState.Stopped;
      }
    }
    /// <summary>
    /// Moves to the next available input source.
    /// </summary>
    /// <remarks>
    /// This method blocks the calling thread as long as the switching to the new input source lasts. This includes
    /// the crossfading duration (if crossfading is done) or the fading out (if no crossfading is done).
    /// </remarks>
    protected void MoveToNextInputSource_Sync()
    {
      // TODO: Insert gap between tracks if we are in playback mode Normal
      IInputSource inputSource = PeekNextInputSource();

      if (_playbackSession != null)
      {
        BassCDTrackInputSource bcdtisNew = inputSource as BassCDTrackInputSource;
        IInputSource currentInputSource = _playbackSession.CurrentInputSource;
        BassCDTrackInputSource bcdtisOld = currentInputSource as BassCDTrackInputSource;
        if (bcdtisOld != null && bcdtisNew != null)
        {
          // Special treatment for CD drives: If the new input source is from the same audio CD drive, we must take the stream over
          if (bcdtisOld.SwitchTo(bcdtisNew))
          {
            _playbackSession.IsAwaitingNextInputSource = false;
            ClearNextInputSource();
            return;
          }
        }
        // TODO: Trigger crossfading if CF is configured
        _playbackSession.End(_internalState == InternalPlaybackState.Playing); // Only wait for fade out when we are playing
      }

      _internalState = InternalPlaybackState.Playing;
      if (inputSource == null)
        Log.Debug("No more input sources available.");
      else
        Log.Debug("Playing next input source '{0}'", inputSource);
      if (_playbackSession != null)
      {
        if (_playbackSession.InitializeWithNewInputSource(inputSource))
        {
          _playbackSession.Play();
          ClearNextInputSource();
          return;
        }
        _playbackSession.Dispose();
        _playbackSession = null;
      }

      if (inputSource == null)
      {
        Ended();
        return;
      }

      _playbackSession = PlaybackSession.Create(_controller);
      if (_playbackSession == null)
      {
        _internalState = InternalPlaybackState.Stopped;
        return;
      }
      _playbackSession.Play();

      _internalState = InternalPlaybackState.Playing;
      _controller.StateReady();
    }