private void bTogglePlay_Click(object sender, EventArgs e) { if (mediaplayer != null) { if (mediaplayer.IsStopped || mediaplayer.IsPausing) { if (mediaplayer.IsStopped) { // Select MediaItem and start playing if (lbPlaylist.SelectedIndex < 0 && lbPlaylist.Items.Count > 0) { lbPlaylist.SelectedIndex = 0; } if (lbPlaylist.SelectedIndex >= 0) { mediaplayer.ChangeCurrentMediaItemIndex(lbPlaylist.SelectedIndex, false); } } mediaplayer.Play(); bTogglePlay.Text = "Pause"; } else if (mediaplayer.IsPlaying) { mediaplayer.Pause(); bTogglePlay.Text = "Play"; } } }
private void ExecMenu() { string ch = "\0"; do { ch = Console.ReadKey(true).KeyChar.ToString().ToUpper(); switch (ch) { case "P": //play/pause if (mediaplayer.IsStopped || mediaplayer.IsPausing) { mediaplayer.Play(); } else if (mediaplayer.IsPlaying) { mediaplayer.Pause(); } break; case "Z": //stop if (mediaplayer.IsPlaying || mediaplayer.IsPausing) { mediaplayer.Stop(); } break; case ",": case "<": // previous mediaplayer.Previous(); break; case ".": case ">": // next mediaplayer.Next(); break; case "S": // Seek if (mediaplayer.IsPlaying) { mediaplayer.Seek(15 * 1000); } break; case "+": if (mediaplayer.Volume < 100) { mediaplayer.Volume = Convert.ToByte(mediaplayer.Volume + 1); } break; case "-": if (mediaplayer.Volume > 0) { mediaplayer.Volume = Convert.ToByte(mediaplayer.Volume - 1); } break; } //switch } while (ch != "Q"); }
/// <summary> /// Pause musicplayer /// </summary> public void Pause() { if (State != PlayerState.Pause) { Mediaplayer.Pause(); State = PlayerState.Pause; } }