...
1 private MediaPlayer player; 2 3 public MainWindow() 4 { 5 InitializeComponent(); 6 player = new MediaPlayer(); 7 } 8 9 private void ButtonOfOpen_Click(object sender, RoutedEventArgs e) 10 { 11 player.Open(new Uri(@"C:\Users\Ares\Desktop\Sound\TfrAlarm.mp3", UriKind.RelativeOrAbsolute)); 12 DispatcherTimer timer = new DispatcherTimer(); 13 timer.Interval = TimeSpan.FromSeconds(1); 14 timer.Tick += timer_Tick; 15 timer.Start(); 16 } 17 18 void timer_Tick(object sender, EventArgs e) 19 { 20 if (player.Source == null) return; 21 22 labelofTime.Content = String.Format("{0}/{1}", player.Position.ToString(@"mm\:ss"), player.NaturalDuration.TimeSpan.ToString(@"mm\:ss")); 23 } 24 25 private void ButtonOfPlay_Click(object sender, RoutedEventArgs e) 26 { 27 player.Play(); 28 } 29 30 private void ButtonOfPause_Click(object sender, RoutedEventArgs e) 31 { 32 player.Pause(); 33 } 34 35 private void ButtonOfStop_Click(object sender, RoutedEventArgs e) 36 { 37 player.Stop(); 38 }