WPF audio playback MediaPlayer, wpf audio mediaplayer

Source: Internet
Author: User

WPF audio playback MediaPlayer, wpf audio mediaplayer

 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         }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.