예제 #1
0
 /// <summary>
 /// Sets the position of <see cref="_currentFile"/> to its beginning
 /// </summary>
 private void ResetPosition()
 {
     if (_currentFile.CanSeek)
     {
         _currentFile.SetPosition(new TimeSpan());
     }
 }
예제 #2
0
 public void JumpTo(TimeSpan position)
 {
     if (PlaybackState == PlaybackState.Playing)
     {
         _waveSource.SetPosition(position);
     }
 }
예제 #3
0
        public bool SwapDevice(Device d)
        {
            if (_soundOut != null)
            {
                bool     wasPlaying = IsPlaying;
                bool     wasPaused  = Paused;
                TimeSpan pos        = Position;
                outputDevice = d;

                if (wasPlaying || wasPaused)
                {
                    _soundOut.Stop();
                }

                LoadSoundOut();
                _waveSource.SetPosition(pos);

                if (wasPlaying)
                {
                    _soundOut.Play();
                }
                else if (wasPaused)
                {
                    _soundOut.Play();
                    _soundOut.Pause();
                }
            }

            return(true);
        }
예제 #4
0
        public void seek(long newPosition)
        {
            // Restricted to seeking to even second boundaries
            TimeSpan ts = new TimeSpan(0, 0, (int)(newPosition / source.WaveFormat.SampleRate / source.WaveFormat.Channels));

            source.SetPosition(ts);
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 public void Stop()
 {
     if (_soundOut != null)
     {
         _waveSource.SetPosition(TimeSpan.Zero);
         _soundOut.Stop();
     }
 }
예제 #6
0
        //Progress changing
        private void progressBar_MouseClick(object sender, MouseEventArgs e)
        {
            if (db > 0)
            {
                double MousePosition    = e.X;
                double ratio            = MousePosition / progressBar.Width;
                double progressBarValue = ratio * progressBar.Maximum;
                this.progressBar.Value = (int)progressBarValue;

                TimeSpan position = new TimeSpan(0, 0, (int)progressBarValue);
                audio.SetPosition(position);
            }
        }
예제 #7
0
        private void tbar_pos_Scroll(object sender, EventArgs e)
        {
            if (waveSource == null)
            {
                return;
            }
            if (!waveSource.CanSeek)
            {
                return;
            }

            waveSource.SetPosition(TimeSpan.FromMilliseconds(tbar_pos.Value));
        }
예제 #8
0
파일: SyncrPlayer.cs 프로젝트: msf567/Syncr
        public void SeekScore(float position)
        {
            if (IsPlaying && currentMusic != null)
            {
                int newPosInMillis = (int)(currentMusic.GetLength().TotalMilliseconds *position);
                Console.WriteLine("Seeking to " + newPosInMillis);

                currentMusic.SetPosition(TimeSpan.FromMilliseconds(newPosInMillis));
                UpdateMillis();

                while (CurrentScore.Triggers[triggerIndex].time < CurrentMillis)
                {
                    SkipNextTrigger();
                }
            }
        }
예제 #9
0
        private static void AddTimeSpan(IWaveSource source, MediaFoundationEncoder mediaFoundationEncoder, TimeSpan startTimeSpan, TimeSpan endTimeSpan)
        {
            source.SetPosition(startTimeSpan);

            int  read          = 0;
            long bytesToEncode = source.GetRawElements(endTimeSpan - startTimeSpan);

            var buffer = new byte[source.WaveFormat.BytesPerSecond];

            while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
            {
                int bytesToWrite = (int)Math.Min(read, bytesToEncode);
                mediaFoundationEncoder.Write(buffer, 0, bytesToWrite);
                bytesToEncode -= bytesToWrite;
            }
        }
예제 #10
0
        public void Seek(double TrackPercent)
        {
            if (CurrentTrack == null)
            {
                return;
            }

            if (TrackPercent < 0 || TrackPercent > 1)
            {
                return;
            }

            TimeSpan targetTime = _waveSource.GetLength() * TrackPercent;

            _waveSource.SetPosition(targetTime);
            Seeked?.Invoke(TrackPercent);
        }
예제 #11
0
 private void trackbar_progress_ValueChanged(object sender, EventArgs e)
 {
     soundSource.SetPosition(TimeSpan.FromSeconds(trackbar_progress.Value));
 }
예제 #12
0
 public void Detener() //detiene una canción
 {
     _output.Stop();
     _sound.SetPosition(TimeSpan.Zero);
 }
예제 #13
0
 public void Detener() //detiene una canción
 {
     _salida.Pause();
     _sonido.SetPosition(TimeSpan.Zero);
 }
예제 #14
0
        private void ttbbPrev_Click(object sender, ThumbnailButtonClickedEventArgs e)
        {
            Changing = true;
            player.Stop();
            t.Stop();
            if (ActualFileIndex == 0)
                ActualFileIndex = Playlist.Count - 1;
            else
                ActualFileIndex--;

            GetAndFillWithSongInfo();

            source = CodecFactory.Instance.GetCodec(Playlist[ActualFileIndex]);
            if (playerInit)
            {
                ttbbPlayPause.Icon = Icon.FromHandle(ToolbarIcons.ic_play_arrow_white_18dp.GetHicon());
                ttbbPlayPause.Tooltip = "Wznów odtwarzanie";
                mbtnPlayPause.Image = PlayerControlIcons.ic_pause_grey600_48dp;
                player.Initialize(source);
                source.SetPosition(new TimeSpan(0, 0, 0));
                t.Start();
                player.Play();
                mtbTime.Maximum = Convert.ToInt32(source.GetLength().TotalSeconds);
                mtbTime.Value = 0;
            }
        }
예제 #15
0
        private void player_Stopped(object sender, PlaybackStoppedEventArgs e)
        {
            if (!Changing)
            {
                //MessageBox.Show(e.Exception.ToString());
                t.Stop();
                if (ActualFileIndex == Playlist.Count - 1)
                    ActualFileIndex = 0;
                else
                    ActualFileIndex++;

                GetAndFillWithSongInfo();

                source = CodecFactory.Instance.GetCodec(Playlist[ActualFileIndex]);
                if (playerInit)
                {
                    ttbbPlayPause.Icon = Icon.FromHandle(ToolbarIcons.ic_play_arrow_white_18dp.GetHicon());
                    ttbbPlayPause.Tooltip = "Wznów odtwarzanie";
                    player.Initialize(source);
                    source.SetPosition(new TimeSpan(0, 0, 0));
                    t.Start();
                    player.Play();
                    mtbTime.Maximum = Convert.ToInt32(source.GetLength().TotalSeconds);
                    mtbTime.Value = 0;
                }
            }
        }
예제 #16
0
 public void Stop()
 {
     _soundOut.Stop();
     _soundSource.SetPosition(TimeSpan.Zero);
 }