/// <summary> /// Sets the position of <see cref="_currentFile"/> to its beginning /// </summary> private void ResetPosition() { if (_currentFile.CanSeek) { _currentFile.SetPosition(new TimeSpan()); } }
public void JumpTo(TimeSpan position) { if (PlaybackState == PlaybackState.Playing) { _waveSource.SetPosition(position); } }
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); }
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); }
/// <summary> /// /// </summary> public void Stop() { if (_soundOut != null) { _waveSource.SetPosition(TimeSpan.Zero); _soundOut.Stop(); } }
//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); } }
private void tbar_pos_Scroll(object sender, EventArgs e) { if (waveSource == null) { return; } if (!waveSource.CanSeek) { return; } waveSource.SetPosition(TimeSpan.FromMilliseconds(tbar_pos.Value)); }
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(); } } }
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; } }
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); }
private void trackbar_progress_ValueChanged(object sender, EventArgs e) { soundSource.SetPosition(TimeSpan.FromSeconds(trackbar_progress.Value)); }
public void Detener() //detiene una canción { _output.Stop(); _sound.SetPosition(TimeSpan.Zero); }
public void Detener() //detiene una canción { _salida.Pause(); _sonido.SetPosition(TimeSpan.Zero); }
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; } }
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; } } }
public void Stop() { _soundOut.Stop(); _soundSource.SetPosition(TimeSpan.Zero); }