private void Update(object sender, EventArgs e) { TimeSpan ts, ts2; TStreamTime pos = new TStreamTime(); TStreamInfo info = new TStreamInfo(); TStreamTime time = new TStreamTime(); player2.GetPosition(ref pos); player2.GetStreamInfo(ref info); time = info.Length; ts = TimeSpan.FromSeconds(Convert.ToDouble(pos.sec.ToString())); ts2 = TimeSpan.FromSeconds(Convert.ToDouble(time.sec.ToString())); if (Convert.ToInt32(time.sec) > 0) { if (Convert.ToInt32(time.sec) - Convert.ToInt32(pos.sec) <= 0) { frm1.Invoke((MethodInvoker) delegate { frm1.Forward(); }); } Form1.ChangeNameLabel(ts + "/" + ts2); Form1.ChangePositionBar(Convert.ToInt32(pos.sec) * 100 / Convert.ToInt32(time.sec)); } }
/// <summary> /// 定位向后播放方法 /// </summary> /// <param name="mTime"></param> public void SeekBackward(int mValue) { TStreamTime mTime = new TStreamTime(); mTime.sec = Convert.ToUInt32(mValue); mZPlay.Seek(TTimeFormat.tfSecond, ref mTime, TSeekMethod.smFromCurrentBackward); }
/// <summary> /// 循环播放当前配置文件中的音频文件,告警信息时候调用 /// </summary> public void Play() { try { string source = string.Empty; bool enabled = false; VoiceXmlHelper.ReadFromXML(out source, out enabled); if (File.Exists(source) && enabled) { m_currentPlayer.OpenFile(source, TStreamFormat.sfAutodetect); // 循环播放 TStreamInfo info = new TStreamInfo(); m_currentPlayer.GetStreamInfo(ref info); TStreamTime time = new TStreamTime(); time.sec = 0; TStreamTime timeEnd = new TStreamTime(); timeEnd.sec = info.Length.sec; m_currentPlayer.PlayLoop(TTimeFormat.tfSecond, ref time, TTimeFormat.tfSecond, ref timeEnd, Int32.MaxValue, true); m_bIsCurrentFromWarningInfo = true; //Play(source); } } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(exp.Message); } finally { } }
/// <summary> /// 将一个int类型转化为TStreamTime /// </summary> /// <returns></returns> public static TStreamTime ConvertIntToTStreamTime(int mPosition) { TStreamTime mTime = new TStreamTime(); mTime.sec = Convert.ToUInt32(mPosition); return(mTime); }
private TStreamTime GetPosition(ref ZPlay player) { TStreamTime position = new TStreamTime(); player?.GetPosition(ref position); return(position); }
private void Button11_Click(object sender, System.EventArgs e) { TStreamTime startpos = new TStreamTime(); TStreamTime endpos = new TStreamTime(); player.GetPosition(ref startpos); endpos.sec = System.Convert.ToUInt32(startpos.sec + 2); player.PlayLoop(TTimeFormat.tfSecond, ref startpos, TTimeFormat.tfSecond, ref endpos, 3, true); }
public void Seek(uint ToSeconds) { TStreamTime seekto = new TStreamTime() { sec = ToSeconds }; this.player.Seek(TTimeFormat.tfSecond, ref seekto, TSeekMethod.smFromBeginning); }
/// <summary> /// 将一个TStreamTime类型转换为字符串 /// </summary> /// <param name="mTime"></param> /// <returns></returns> public static string ConvertTStreamTimeToString(TStreamTime mTime) { //从TStreamTime类型中获取毫秒 uint mSeconds=mTime.sec; //计算分钟数 int mm=(int)(Convert.ToInt32(mSeconds)/60); int ss=(int)(Convert.ToInt32(mSeconds)%60); //生成两位时间的字符格式 string mFormat = string.Format("00"); return mm.ToString(mFormat) + ":" + ss.ToString(mFormat); }
/// <summary> /// 将一个TStreamTime类型转换为字符串 /// </summary> /// <param name="mTime"></param> /// <returns></returns> public static string ConvertTStreamTimeToString(TStreamTime mTime) { //从TStreamTime类型中获取毫秒 uint mSeconds = mTime.sec; //计算分钟数 int mm = (int)(Convert.ToInt32(mSeconds) / 60); int ss = (int)(Convert.ToInt32(mSeconds) % 60); //生成两位时间的字符格式 string mFormat = string.Format("00"); return(mm.ToString(mFormat) + ":" + ss.ToString(mFormat)); }
private void Button13_Click(object sender, System.EventArgs e) { int left = 0; int right = 0; TStreamTime startpos = new TStreamTime(); TStreamTime endpos = new TStreamTime(); player.GetPlayerVolume(ref left, ref right); player.GetPosition(ref startpos); endpos.sec = System.Convert.ToUInt32(startpos.sec + 5); player.SlideVolume(TTimeFormat.tfSecond, ref startpos, left, right, TTimeFormat.tfSecond, ref endpos, 100, 100); }
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(); } } } }
private void ProgressBar1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e) { TStreamTime newpos = new TStreamTime(); TStreamInfo Info = new TStreamInfo(); player.GetStreamInfo(ref Info); newpos.sec = System.Convert.ToUInt32(e.X * Info.Length.sec / System.Convert.ToDouble(((ProgressBar)sender).Size.Width)); player.Seek(TTimeFormat.tfSecond, ref newpos, TSeekMethod.smFromBeginning); }
public void OnRewindPictureBoxOnClick(object sender, EventArgs args) { if (Player == null) { return; } 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); }
public void Play() { this.player.GetStatus(ref this.stream_status); if (this.stream_status.fPlay && this.stream_status.fPause) { return; } TStreamTime Position = new TStreamTime(); this.player.GetStatus(ref this.stream_status); if (this.stream_status.fPause) { Position.sec = 0U; this.player.Seek(TTimeFormat.tfSecond, ref Position, TSeekMethod.smFromBeginning); } this.player.StartPlayback(); }
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(); }
public void SeekForward(uint seconds) { this.player.GetStreamInfo(ref this.stream_info); this.player.GetStatus(ref this.stream_status); if (this.player == null) { return; } TStreamTime time = new TStreamTime(); this.player.GetPosition(ref time); if (time.sec + seconds <= this.stream_info.Length.sec && this.stream_status.fPlay) { TStreamTime seekto = new TStreamTime() { sec = seconds }; this.player.Seek(TTimeFormat.tfSecond, ref seekto, TSeekMethod.smFromCurrentForward); } }
public bool ReleaseHandle() { try { if (!this.player.OpenFile(this.current_file, TStreamFormat.sfAutodetect)) { return(false); } if (this.wasPlaying) { TStreamTime Position = new TStreamTime(); Position.sec = this.stream_time.sec; this.player.StartPlayback(); this.player.Seek(TTimeFormat.tfSecond, ref Position, TSeekMethod.smFromBeginning); this.wasPlaying = true; } return(true); } catch (Exception ex) { return(false); } }
private extern static int zplay_Seek(uint objptr, TTimeFormat fFormat, ref TStreamTime pTime, TSeekMethod nMoveMethod);
private extern static int zplay_PlayLoop(uint objptr, int fFormatStartTime, ref TStreamTime pStartTime, int fFormatEndTime, ref TStreamTime pEndTime, uint nNumOfCycles, uint fContinuePlaying);
public bool PlayLoop(TTimeFormat TimeFormatStart, ref TStreamTime StartPosition, TTimeFormat TimeFormatEnd, ref TStreamTime EndPosition, uint NumberOfCycles, bool ContinuePlaying);
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 }
public bool SlideVolume(TTimeFormat TimeFormatStart, ref TStreamTime TimeStart, int StartVolumeLeft, int StartVolumeRight, TTimeFormat TimeFormatEnd, ref TStreamTime TimeEnd, int EndVolumeLeft, int EndVolumeRight) { return zplay_SlideVolume(objptr, TimeFormatStart, ref TimeStart, StartVolumeLeft, StartVolumeRight, TimeFormatEnd, ref TimeEnd, EndVolumeLeft, EndVolumeRight) == 1; }
public bool Seek(TTimeFormat TimeFormat, ref TStreamTime Position, TSeekMethod MoveMethod) { return zplay_Seek(objptr, TimeFormat, ref Position, MoveMethod) == 1; }
/// <summary> /// 将一个int类型转化为TStreamTime /// </summary> /// <returns></returns> public static TStreamTime ConvertIntToTStreamTime(int mPosition) { TStreamTime mTime = new TStreamTime(); mTime.sec = Convert.ToUInt32(mPosition); return mTime; }
public bool Seek(TTimeFormat TimeFormat, ref TStreamTime Position, TSeekMethod MoveMethod);
public void GetPosition(ref TStreamTime time);
public bool SlideVolume(TTimeFormat TimeFormatStart, ref TStreamTime TimeStart, int StartVolumeLeft, int StartVolumeRight, TTimeFormat TimeFormatEnd, ref TStreamTime TimeEnd, int EndVolumeLeft, int EndVolumeRight);
private extern static int zplay_SlideVolume(uint objptr, TTimeFormat fFormatStart, ref TStreamTime pTimeStart, int nStartVolumeLeft, int nStartVolumeRight, TTimeFormat fFormatEnd, ref TStreamTime pTimeEnd, int nEndVolumeLeft, int nEndVolumeRight);
public void GetPosition(ref TStreamTime time) { zplay_GetPosition(objptr, ref time); }
/// <summary> /// 将一个TStreamTime转化为int类型 /// </summary> /// <param name="mTime"></param> /// <returns></returns> public static int ConvertTStreamTimeToInt(TStreamTime mTime) { return Convert.ToInt32(mTime.sec); }
public bool PlayLoop(TTimeFormat TimeFormatStart, ref TStreamTime StartPosition, TTimeFormat TimeFormatEnd, ref TStreamTime EndPosition, uint NumberOfCycles, bool ContinuePlaying) { uint continueplay = 0; if (ContinuePlaying) { continueplay = 1; } else { continueplay = 0; } return zplay_PlayLoop(objptr, System.Convert.ToInt32((int)(TimeFormatStart)), ref StartPosition, System.Convert.ToInt32((int)(TimeFormatEnd)), ref EndPosition, NumberOfCycles, continueplay) == 1; }
private void Timer1_Tick(object sender, System.EventArgs e) { TStreamTime pos = new TStreamTime(); player.GetPosition(ref pos); if(ProgressBar1.Maximum > pos.sec) ProgressBar1.Value = System.Convert.ToInt32((int)(pos.sec)); position.Text = System.String.Format("{0,2:G}", pos.hms.hour) + " : " + System.String.Format("{0,2:G}", pos.hms.minute) + " : " + System.String.Format("{0,2:G}", pos.hms.second) + " : " + System.String.Format("{0,3:G}", pos.hms.millisecond); TStreamStatus Status = new TStreamStatus(); player.GetStatus(ref Status); statuslabel1.Text = "Eq:" + System.Environment.NewLine + "Fade:" + System.Environment.NewLine + "Echo:" + System.Environment.NewLine + "Bitrate:" + System.Environment.NewLine + "Vocal cut:" + System.Environment.NewLine + "Side cut:"; statuslabel2.Text = "Loop:" + System.Environment.NewLine + "Reverse:" + System.Environment.NewLine + "Play:" + System.Environment.NewLine + "Pause:" + System.Environment.NewLine + "Channel mix:" + System.Environment.NewLine + "Load:"; statusvalue1.Text = System.Convert.ToString(Status.fEqualizer) + System.Environment.NewLine + System.Convert.ToString(Status.fSlideVolume) + System.Environment.NewLine + System.Convert.ToString(Status.fEcho) + System.Environment.NewLine + System.Convert.ToString(player.GetBitrate(false)) + System.Environment.NewLine + System.Convert.ToString(Status.fVocalCut) + System.Environment.NewLine + System.Convert.ToString(Status.fSideCut); TStreamLoadInfo load = new TStreamLoadInfo(); player.GetDynamicStreamLoad(ref load); statusvalue2.Text = System.Convert.ToString(Status.nLoop) + System.Environment.NewLine + System.Convert.ToString(Status.fReverse) + System.Environment.NewLine + System.Convert.ToString(Status.fPlay) + System.Environment.NewLine + System.Convert.ToString(Status.fPause) + System.Environment.NewLine + System.Convert.ToString(Status.fChannelMix) + System.Environment.NewLine + System.Convert.ToString(load.NumberOfBuffers); if (Status.fSlideVolume != false) { BlockLeft = true; BlockRight = true; int Left = 0; int Right = 0; player.GetPlayerVolume(ref Left, ref Right); leftplayervolume.Value = 100 - Left; rightplayervolume.Value = 100 - Right; } if (FadeFinished) { int Left = 0; int Right = 0; player.GetPlayerVolume(ref Left, ref Right); leftplayervolume.Value = 100 - Left; rightplayervolume.Value = 100 - Right; FadeFinished = false; } if(NextSong) { showinfo(); NextSong = false; } }
/// <summary> /// 将一个TStreamTime转化为int类型 /// </summary> /// <param name="mTime"></param> /// <returns></returns> public static int ConvertTStreamTimeToInt(TStreamTime mTime) { return(Convert.ToInt32(mTime.sec)); }
private void Button10_Click(object sender, System.EventArgs e) { TStreamTime newpos = new TStreamTime(); newpos.sec = 5; player.Seek(TTimeFormat.tfSecond, ref newpos, TSeekMethod.smFromCurrentForward); }
private extern static void zplay_GetPosition(uint objptr, ref TStreamTime pTime);