Ejemplo n.º 1
0
        /// <summary>
        ///     (Re-)Starts the _CurrentPlaylistElement
        /// </summary>
        private static void _StartSong()
        {
            Debug.Assert(_CurrentPlaylistElement != null);

            //If current song same as loaded restart only
            if (_BGPlayer.SoundLoaded && _CurrentPlaylistElement.MusicFilePath == _BGPlayer.FilePath)
            {
                _BGPlayer.Stop();
                _BGPlayer.Play();
                return;
            }

            //otherwhise load
            if (!_CurrentPlaylistElement.HasMetaData)
            {
                _BGPlayer.Load(_CurrentPlaylistElement.MusicFilePath, 0f, true);
            }
            else
            {
                //Seek to #Start-Tag, if found
                float start = 0f;
                if (_CurrentPlaylistElement.Start > 0.001 && CConfig.Config.Sound.BackgroundMusicUseStart == EOffOn.TR_CONFIG_ON)
                {
                    start = _CurrentPlaylistElement.Start;
                }
                _BGPlayer.Load(_CurrentPlaylistElement.Song, start, true);
            }
        }
Ejemplo n.º 2
0
        public static void LoadPreview(CSong song, float start = -1f)
        {
            if (song == null)
            {
                throw new ArgumentNullException("song");
            }

            if (!IsPlayingPreview)
            {
                Pause();
                CSound.SetGlobalVolume(CConfig.PreviewMusicVolume);
            }

            bool songChanged = _CurPlayer.SongID != song.ID;

            _PreviewPlayer.Load(song);


            //Change song position only if song is changed or near to end
            if (songChanged || _CurPlayer.Position + 30 < _CurPlayer.Length)
            {
                _PreviewStartHelperTask = new Task(() =>
                {
                    float length = _PreviewPlayer.Length;
                    if (length < 1)
                    {
                        length = 30; // If length is unknow or invalid assume a length of 30s
                    }
                    if (start < 0)
                    {
                        start = (song.Preview.Source == EDataSource.None) ? length / 4f : song.Preview.StartTime;
                    }
                    if (start > length - 5f)
                    {
                        start = Math.Max(0f, Math.Min(length / 4f, length - 5f));
                    }
                    if (start >= 0.5f)
                    {
                        start -= 0.5f;
                    }

                    _PreviewPlayer.Position = start;
                    Play();
                });
                _CurPlayer = _PreviewPlayer;
            }
            else
            {
                _PreviewStartHelperTask.Dispose();
                _PreviewStartHelperTask = null;
                _PreviewPlayer.Position = _CurPlayer.Position;
                _CurPlayer = _PreviewPlayer;
                Play();
            }
        }
Ejemplo n.º 3
0
 public static void StopPreview()
 {
     if (!IsPlayingPreview)
     {
         return;
     }
     Stop();
     _CurPlayer = _BGPlayer;
     if (_MusicSource != EBackgroundMusicSource.TR_CONFIG_NO_OWN_MUSIC)
     {
         _CurPlayer.Load(CSongs.GetSong(_PreviewPlayer.SongID));
         _CurPlayer.Position = _PreviewPlayer.Position;
     }
     CSound.SetGlobalVolume(CConfig.BackgroundMusicVolume);
 }