protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); _timer?.Dispose(); Player?.StopPlayback(); Player?.Dispose(); Player = null; (Owner as MainForm)?.SetSecondForm(null); }
static void Main(string[] args) { Console.WriteLine("Playing test.mp3. Press Q to quit.\n"); // create ZPlay class ZPlay player = new ZPlay(); // open file if (player.AddFile("1.mp3", TStreamFormat.sfAutodetect) == false) { Console.WriteLine(player.GetError()); return; } // get song length TStreamInfo info = new TStreamInfo(); player.GetStreamInfo(ref info); Console.WriteLine("Length: {0:G}:{1:G}:{2:G}:{3:G}", info.Length.hms.hour, info.Length.hms.minute, info.Length.hms.second, info.Length.hms.millisecond); // start playing player.StartPlayback(); TStreamStatus status = new TStreamStatus(); TStreamTime time = new TStreamTime(); status.fPlay = true; while (status.fPlay) { player.GetPosition(ref time); Console.Write("Pos: {0:G}:{1:G}:{2:G}:{3:G}\r", time.hms.hour, time.hms.minute, time.hms.second, time.hms.millisecond); player.GetStatus(ref status); System.Threading.Thread.Sleep(50); if (Console.KeyAvailable) { var cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.Q) { player.StopPlayback(); } } } }
/// <summary> /// 停止播放当前的音频文件 /// </summary> public void Stop() { try { if (null != m_currentPlayer) { m_currentPlayer.StopPlayback(); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } }
private void UpdateProgressBar(ref ZPlay player) { int positionMilisec = Convert.ToInt32(GetPosition(ref player).ms); if (playbackProgressBarAdv.Maximum >= positionMilisec) { playbackProgressBarAdv.Value = positionMilisec; } if (IsAudioTrackEndReached(ref player)) { NormalizeMetronomeToggleButton(ref player); _metronomePlayer?.StopPlayback(); } }
private void OpenAudioFile(ref ZPlay player) { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Filter = Resources.FileFilters; if (openFileDialog.ShowDialog() == DialogResult.OK) // Test result. { try { player?.StopPlayback(); _isPaused = false; _isPlaying = false; if (player == null) { player = new ZPlay(); } if (player.OpenFile(openFileDialog.FileName, TStreamFormat.sfAutodetect) == false) { MessageBox.Show($@"ERROR {this.Player.GetError()}"); return; } AdjustPlayerParams(ref player); SetProgressBar(ref player); ResetToggleButtons(ref player); } catch (IOException exception) { Console.WriteLine(exception.StackTrace); throw; } } } }
private void UpdateProgressBar(ref ZPlay player) { int positionMilisec = Convert.ToInt32(GetPosition(ref player).ms); if (playbackProgressBarAdv.Maximum >= positionMilisec) { playbackProgressBarAdv.Value = positionMilisec; } if (IsAudioTrackEndReached(ref player)) { NormalizeMetronomeToggleButton(ref player); //NormalizeReversePlaybackToggleButton(ref player); //if (metronomeToggleButton.InvokeRequired) // metronomeToggleButton.Invoke((MethodInvoker) (() => // _metronomePlayer?.StopPlayback())); //else //{ // _metronomePlayer?.StopPlayback(); //} _metronomePlayer?.StopPlayback(); } }
private void Button5_Click(object sender, System.EventArgs e) { player.StopPlayback(); }
private void SoundPlayer_FormClosing(object sender, FormClosingEventArgs e) { player.StopPlayback(); player.Close(); }
void ChkWavesDoubleClick(object sender, EventArgs e) { gPlayer.StopPlayback(); gPlayer.StartPlayback(); textBox1.Focus(); }
public void Stop() { player2.StopPlayback(); }
public void Run() { zPlayBuffer = new CircularBlockBuffer(); zPlay = new ZPlay(); netConnection = new NetConnection(); netConnection.OnDisconnect += new NC_OnDisconnect(OnDisconnect); netConnection.OnTick += new NC_OnTick(NC_OnTick); try { int result = -1; // This is to connect to default vod app netConnection.Connect(new ServerLink("rtmp://localhost:1935/vod"), new NC_ResultCallBackConnect((sender, success) => { // Runs in RTMP thread (NOT MainThread!!!) Console.WriteLine("NetConnection.Connect => Success=" + success.ToString()); if (success) { result = 1; } else { result = 0; } })); // Wait until we are connected (needed because we run async) while (result == -1) { Thread.Sleep(100); } //while // Succes for connecting to rtmp server if (result == 1) { NetStream netStream = new NetStream(netConnection); netStream.OnStatus += new NS_OnStatus(NS_OnStatus); netStream.OnAudioPacket += new NC_OnMediaPacket(NC_OnMediaPacket); netStream.WaitForValidStream_ID(4000); // wait max 4 seconds for the netstream to become valid (for real test connect to event) // This is to get and MP3 stream netStream.Play("Comfort_Fit_-_03_-_Sorry.mp3", 0, -1, true); } Console.WriteLine("Press enter to stop."); Console.ReadLine(); } finally { // Cleanup if (netConnection != null) { netConnection.Close(); netConnection = null; } if (zPlay != null) { TStreamStatus status = new TStreamStatus(); zPlay.GetStatus(ref status); if (status.fPlay) { zPlay.StopPlayback(); } zPlay.Close(); zPlay = null; } if (zPlayBuffer != null) { zPlayBuffer = null; } } }
private void RegisterControlsEvents() { #region Menu Buttons loadAudioFileButtonAdv.Click += (sender, args) => OpenAudioFile(ref Player); //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); }; // freeeeeeeeeeeee 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); }; // periooooooooooooooo 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); }; //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(); #region _secondForm Control Buttons ReplayPictureBox.Click += OnReplayPictureBoxOnClick; PlayResumePictureBox.Click += OnPlayResumePictureBoxOnClick; PausePictureBox.Click += OnPausePictureBoxOnClick; StopPictureBox.Click += OnStopPictureBoxOnClick; RewindPictureBox.Click += OnRewindPictureBoxOnClick; FastForwardPictureBox.Click += OnFastForwardPictureBoxOnClick; #endregion }