예제 #1
0
        /// <summary>
        /// Pres the buffer next.
        /// </summary>
        private void PreBufferNext()
        {
            var errorCount = 0;

            while (preBuffered.Count < prebufferSongs.Value)
            {
                var next = playlistService.Next();
                if (null == next)
                {
                    break;
                }
                var container = new TrackContainer(player, next);
                try { container.Preload(); }
                catch (Exception e)
                {
                    container.Dispose();
                    ++errorCount;
                    LogException(e, MethodBase.GetCurrentMethod());
                    LogWarning("File Was: {0}", container.File.Filename);
                    if (errorCount >= 50)
                    {
                        LogCritical("Too many errors while prebuffering, giving up...");
                        break;
                    }
                    continue;
                }
                preBuffered.Add(container);
                LogInformation("PlayerService has {0} files PreBuffered", preBuffered.Count);
            }
        }
예제 #2
0
        public virtual void Play(ITrack track)
        {
            var oldCurrent = CurrentTrack;
            var newChannel = new TrackContainer(track);

            try
            {
                newChannel.Preload();
            }
            catch (Exception e)
            {
                newChannel.Dispose();
                LogException(e, MethodBase.GetCurrentMethod());
                LogWarning("Track Was: {0}", track);
                return;
            }
            SwapChannels(newChannel);

            if (null != oldCurrent)
            {
                PushContainer(oldCurrent);
            }

            playlistService.SetPlaylistIndex(null);
            ReBuffer();
        }
예제 #3
0
        /// <summary>
        /// Plays this instance.
        /// </summary>
        /// <param name="file"></param>
        public virtual void Play(StorableTaggedFile file)
        {
            file.Guard("file");
            var oldCurrent = CurrentTrack;
            var newChannel = new TrackContainer(player, file);

            try
            {
                newChannel.Preload();
            }
            catch (Exception e)
            {
                newChannel.Dispose();
                LogException(e, MethodBase.GetCurrentMethod());
                LogWarning("File Was: {0}", file.Filename);
                return;
            }
            SwapChannels(newChannel);

            if (null != oldCurrent)
            {
                PushContainer(oldCurrent);
            }

            var index = playlistService.Files.IndexOf(file);

            if (index < 0)
            {
                return;
            }
            playlistService.SetPlaylistIndex(file);
            ReBuffer();
        }
예제 #4
0
        protected virtual void SetActive(StorableTaggedFile file, double offset)
        {
            var container = GetContainer(file);

            if (null == container)
            {
                return;
            }
            CurrentTrack = container;
            container.Seek(offset);
            NotifyNewTrack(container);
            SendProgress();
        }
예제 #5
0
        private TrackContainer GetContainer(StorableTaggedFile file)
        {
            var channel = new TrackContainer(player, file);

            try
            {
                channel.Preload();
            }
            catch
            {
                return(null);
            }
            return(channel);
        }
예제 #6
0
 /// <summary>
 /// Pushes the current.
 /// </summary>
 private void PushContainer(TrackContainer container)
 {
     if (null == CurrentTrack)
     {
         return;
     }
     if (backStack.Count >= maxBackStack.Value)
     {
         for (var i = 0; i < 100 / maxBackStack.Value * 10; ++i)
         {
             backStack.RemoveAt(0);
         }
     }
     TrimBackBuffered();
     backStack.Add(container);
 }
예제 #7
0
 /// <summary>
 /// Swaps the channels.
 /// </summary>
 /// <param name="nextTrack">The next channel.</param>
 /// <returns></returns>
 private bool SwapChannels(TrackContainer nextTrack)
 {
     try { nextTrack.Play(0f); }
     catch (Exception e)
     {
         nextTrack.Dispose();
         LogException(e, MethodBase.GetCurrentMethod());
         return(false);
     }
     if (null != CurrentTrack)
     {
         CrossFade(CurrentTrack, nextTrack);
     }
     else
     {
         FadeIn(nextTrack);
     }
     CurrentTrack = nextTrack;
     NotifyNewTrack(CurrentTrack);
     UpdateState();
     return(true);
 }
예제 #8
0
 /// <summary>
 /// Notifies the new track.
 /// </summary>
 /// <param name="file">The file.</param>
 private void NotifyNewTrack(TrackContainer file)
 {
     publicTransport.ApplicationEventBus.Send(new TrackChangedEvent(file.File, file.Length));
 }