private void UI_PauseButton_Click(object sender, EventArgs e) { if (ready) { player.PausePlayback(); paused = true; } }
public void OnPausePictureBoxOnClick(object sender, EventArgs args) { if (Player == null) { return; } _isPaused = Player.PausePlayback(); _isPlaying = !_isPaused; }
public void SetPlayerPosition(int p) { TStreamStatus status = new TStreamStatus(); if (status.fPlay) { player2.PausePlayback(); } TStreamTime newpos = new TStreamTime(); TStreamInfo info = new TStreamInfo(); TStreamTime time = new TStreamTime(); player2.GetStreamInfo(ref info); time = info.Length; newpos.sec = Convert.ToUInt32(p * time.sec / 100); player2.Seek(TTimeFormat.tfSecond, ref newpos, TSeekMethod.smFromBeginning); player2.StartPlayback(); }
private void Button3_Click(object sender, System.EventArgs e) { player.PausePlayback(); }
private void RegisterControlsEvents() { #region Menu Buttons firstLoadAudioFileButtonAdv.Click += (sender, args) => OpenAudioFile(ref _player); secondLoadAudioFileButtonAdv.Click += (sender, args) => { if (_secondForm == null) { _secondForm = new SecondForm(); } _secondForm.Hide(); using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = Resources.FileFilters; if (openFileDialog.ShowDialog() == DialogResult.OK) // Test result. { try { //_secondForm.Player?.StopPlayback(); _secondForm.SetIsPaused(false); _secondForm.SetIsPlaying(false); if (_secondForm.Player == null) { _secondForm.Player = new ZPlay(); } if (_secondForm.Player.OpenFile(openFileDialog.FileName, TStreamFormat.sfAutodetect) == false) { MessageBox.Show($@"ERROR {_player.GetError()}"); return; } _secondForm.AdjustPlayerParams(ref _secondForm.Player); _secondForm.SetProgressBar(ref _secondForm.Player); _secondForm.ResetToggleButtons(ref _secondForm.Player); } catch (IOException exception) { Console.WriteLine(exception.StackTrace); throw; } } } _secondForm.Show(this); }; //secondLoadAudioFileButtonAdv.Click += // (sender, args) => // { // OpenAudioFile(secondAxWindowsMediaPlayer, ref _secondAudioFilePath); // this.Height = 600; // secondAxWindowsMediaPlayer.Location = new Point( // firstAxWindowsMediaPlayer.Left, // secondAxWindowsMediaPlayer.Top // ); // }; #endregion pitchTrackBarEx.MouseUp += (sender, args) => { int pitchValue = ((TrackBarEx)sender).Value; pitchNumericUpDown.Value = pitchValue >= 10 ? pitchValue : 10; }; pitchNumericUpDown.ValueChanged += (sender, args) => { int pitchValue = (int)((NumericUpDown)sender).Value; pitchTrackBarEx.Value = pitchValue; _player?.SetPitch(pitchValue); }; // METRONOME SECTION #region Frequency frequencyTrackBarEx.MouseUp += (sender, args) => { int pitchValue = ((TrackBarEx)sender).Value; frequencyNumericUpDown.Value = pitchValue >= 20 ? pitchValue : 20; }; frequencyNumericUpDown.ValueChanged += (sender, args) => { int pitchValue = (int)((NumericUpDown)sender).Value; frequencyTrackBarEx.Value = pitchValue; _metronomePlayer?.SetPitch(pitchValue); }; #endregion #region Periodicity periodicityTrackBarEx.MouseUp += (sender, args) => { int tempoValue = ((TrackBarEx)sender).Value; //periodicityTextBox.Text = $@"{BpmToPeriodicity(tempoValue >= 20 ? tempoValue : 20)}"; periodicityTextBox.Text = $@"{BpmToPeriodicity(periodicityTrackBarEx.Maximum - tempoValue + periodicityTrackBarEx.Minimum)}"; }; periodicityTextBox.TextChanged += (sender, args) => { decimal periodicityValue = decimal.Parse(periodicityTextBox.Text); periodicityTrackBarEx.Value = periodicityTrackBarEx.Maximum - PeriodicityToBPM(periodicityValue) + periodicityTrackBarEx.Minimum; _metronomePlayer?.SetTempo(periodicityTrackBarEx.Maximum - periodicityTrackBarEx.Value + periodicityTrackBarEx.Minimum); }; #endregion //rateTrackBarEx.Click += (sender, args) => //{ // int rateValue = ((TrackBarEx) sender).Value; // _player?.SetTempo(rateValue); //}; tempoTrackBarEx.MouseUp += (sender, args) => { int tempoValue = ((TrackBarEx)sender).Value; tempoNumericUpDown.Value = tempoValue >= 10 ? tempoValue : 10; }; tempoNumericUpDown.ValueChanged += (sender, args) => { int tempoValue = (int)((NumericUpDown)sender).Value; tempoTrackBarEx.Value = tempoValue; _player?.SetTempo(tempoValue); }; reversePlaybackToggleButton.ToggleStateChanged += (sender, args) => { if (_player == null) { return; } ToggleButton self = (ToggleButton)sender; if (self.ToggleState == ToggleButtonState.Active) { _player?.ReverseMode(true); } else { // ToggleButtonState.Inactive _player?.ReverseMode(false); } }; playbackProgressBarAdv.MouseDown += (sender, args) => { //if (args.Button != MouseButtons.Left) // return; TStreamTime newPosition = new TStreamTime(); TStreamInfo info = GetStreamInfo(ref _player); newPosition.ms = Convert.ToUInt32( args.X * info.Length.ms / Convert.ToDouble(((ProgressBarAdv)sender).Size.Width)); _player?.Seek(TTimeFormat.tfMillisecond, ref newPosition, TSeekMethod.smFromBeginning); }; _volumeRadialMenuSlider.SliderValueChanged += (sender, args) => { int volumeLevel = (int)((RadialMenuSlider)sender).SliderValue; if (FFTPictureBox.InvokeRequired) { FFTPictureBox.Invoke( (MethodInvoker)(() => { _player?.SetPlayerVolume(volumeLevel, volumeLevel); })); } else { _player?.SetPlayerVolume(volumeLevel, volumeLevel); } }; volumePictureBox.Click += (sender, args) => { _radialMenu = new RadialMenu(); #region Volume Radial Menu Slider _volumeRadialMenuSlider.MinimumValue = 0; _volumeRadialMenuSlider.MaximumValue = 100; _volumeRadialMenuSlider.SliderValue = 50; _volumeRadialMenuSlider.Text = "VOLUME"; #endregion #region Radial Menu Properties Settings _radialMenu.WedgeCount = 1; _radialMenu.MenuIcon = Image.FromFile($@"{Path.GetDirectoryName(Application.ExecutablePath)}\Icons\Volume-high-icon.png"); _radialMenu.MenuVisibility = true; _radialMenu.PersistPreviousState = true; _radialMenu.UseIndexBasedOrder = true; _radialMenu.RadialMenuSliderDrillDown(_volumeRadialMenuSlider); #region TRASH //_radialMenu.Items.Add(_volumeRadialMenuSlider); //_radialMenu.Icon = Image // .FromFile($@"{Path.GetDirectoryName(Application.ExecutablePath)}\Icons\arrow-back-icon.png"); //ImageCollection ic = new ImageCollection(); //ic.Add(Image.FromFile($@"{Path.GetDirectoryName(Application.ExecutablePath)}\Icons\arrow-back-icon.png")); //_radialMenu.ImageCollection = ic; //_radialMenu.DisplayStyle = DisplayStyle.TextAboveImage; //ImageList imageList = new ImageList(); //string[] files = Directory.GetFiles($@"{Path.GetDirectoryName(Application.ExecutablePath)}\Icons"); //foreach (string file in files) //{ // imageList.Images.Add("volume", Image.FromFile(file)); //} //_radialMenu.ImageList = ImageListAdv.FromImageList(imageList); #endregion #endregion #region Show Radial Menu this.Controls.Add(_radialMenu); _radialMenu.ShowRadialMenu(); //_radialMenu.HidePopup(); //_radialMenu.ShowPopup(new Point()); #endregion _radialMenu.PreviousLevelOpened += (radialMenuSender, opening) => _radialMenu.Dispose(); // Emulate mouse click on 50% Volume on _volumeRadialMenuSlider // because there's a library bug that cannot update value // by .SliderValue property as it's meant to be updated. Point location = MousePosition; LeftMouseClick(location.X - 40, location.Y + 15); }; FFTPictureBox.Paint += (sender, args) => { IntPtr MyDeviceContext = default(IntPtr); MyDeviceContext = args.Graphics.GetHdc(); _player?.DrawFFTGraphOnHDC(MyDeviceContext, 0, 0, FFTPictureBox.Width, FFTPictureBox.Height); args.Graphics.ReleaseHdc(MyDeviceContext); }; playToggleButton.ToggleStateChanged += (sender, args) => { if (_player == null) { return; } if (playToggleButton.ToggleState == ToggleButtonState.Active) { _player.StartPlayback(); //_timer.Start(); return; } else { _player.StopPlayback(); // ToggleButtonState.Inactive //_timer.Stop(); } }; metronomeToggleButton.ToggleStateChanged += (sender, args) => { if (metronomeToggleButton.ToggleState == ToggleButtonState.Active) { if (_metronomePlayer == null) { _metronomePlayer = new ZPlay(); } if (_metronomePlayer.OpenFile(@"Resources\metronom.mp3", TStreamFormat.sfAutodetect) == false) { MessageBox.Show($@"ERROR {_metronomePlayer.GetError()}"); return; } _metronomePlayer.StartPlayback(); _metronomePlayer.SetMasterVolume(100, 100); _metronomePlayer.SetPlayerVolume(100, 100); _isMetronomeSwitch = true; } else { _metronomePlayer.StopPlayback(); // ToggleButtonState.Inactive _isMetronomeSwitch = false; } }; playerVolumeTrackBarEx.Scroll += (sender, args) => { int volumeLevel = ((TrackBarEx)sender).Value; _player?.SetPlayerVolume(volumeLevel, volumeLevel); }; masterVolumeTrackBarEx.Scroll += (sender, args) => { int volumeLevel = ((TrackBarEx)sender).Value; _player?.SetMasterVolume(volumeLevel, volumeLevel); }; this.MouseDown += (sender, mouseEventArgs) => { if (mouseEventArgs.Button == MouseButtons.Left) { ReleaseCapture(); SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); } }; closePictureBox.Click += (sender, args) => this.Close(); // MainForm Control Buttons #region MainForm Control Buttons ReplayPictureBox.Click += (sender, args) => { if (_player == null) { return; } _secondForm?.OnReplayPictureBoxOnClick(null, null); _player.StopPlayback(); _isPlaying = _player.StartPlayback(); _isPaused = false; }; PlayResumePictureBox.Click += (sender, args) => { if (_player == null || _isPlaying) { return; } _secondForm?.OnPlayResumePictureBoxOnClick(null, null); if (_isPaused) { _isPlaying = _player.ResumePlayback(); _isPaused = !_isPlaying; return; } // It was not playing at all or even stopped _isPlaying = _player.StartPlayback(); _isPaused = !_isPlaying; }; PausePictureBox.Click += (sender, args) => { if (_player == null) { return; } _secondForm?.OnPausePictureBoxOnClick(null, null); _isPaused = _player.PausePlayback(); _isPlaying = !_isPaused; }; StopPictureBox.Click += (sender, args) => { if (_player == null) { return; } _secondForm?.OnStopPictureBoxOnClick(null, null); _player.StopPlayback(); _isPaused = false; _isPlaying = false; }; RewindPictureBox.Click += (sender, args) => { if (_player == null) { return; } _secondForm?.OnRewindPictureBoxOnClick(null, null); TStreamTime position = new TStreamTime(); TStreamInfo info = GetStreamInfo(ref _player); position.sec = Convert.ToUInt32(0.05 * info.Length.sec); // 5% _player?.Seek(TTimeFormat.tfSecond, ref position, TSeekMethod.smFromCurrentBackward); }; FastForwardPictureBox.Click += (sender, args) => { if (_player == null) { return; } _secondForm?.OnFastForwardPictureBoxOnClick(null, null); TStreamTime position = new TStreamTime(); TStreamInfo info = GetStreamInfo(ref _player); position.sec = Convert.ToUInt32(0.05 * info.Length.sec); // 5% _player?.Seek(TTimeFormat.tfSecond, ref position, TSeekMethod.smFromCurrentForward); }; #endregion }