码迷,mamicode.com
首页 > Windows程序 > 详细

WPF语音播放MediaPlayer

时间:2016-07-12 10:12:30      阅读:883      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 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         }

 

WPF语音播放MediaPlayer

标签:

原文地址:http://www.cnblogs.com/liunlls/p/MediaPlayer.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!