private void playSound(string str)
{
MediaPlayer player = new MediaPlayer();
try
{
player.Open(new Uri(str, UriKind.Absolute));
player.Play();
}
catch (Exception)
{
player.Stop();
}
//BgMusic bm = new BgMusic();
//bm.BgMusicPath = AppDomain.CurrentDomain.BaseDirectory + "\\Justin Bieber - Up.mp3";
//"C:\\Users\\ZHANGYI\\Desktop\\Justin Bieber - Up.mp3";
//mySoundPlayer.DataContext = bm;
}
private void button2_Click(object sender, RoutedEventArgs e)
{
j = 0;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "音乐文件(*.mp3)|*.mp3|所有文件(*.*)|*.*";
openFileDialog1.ShowDialog();
{
str = openFileDialog1.FileName;
// playSound(str);
//playSound();
// Audio.Play();
}
//OpenFileDialog dialog = new OpenFileDialog();
//if (dialog.ShowDialog() == true)
//{
// Audio.Play();
//}
}
用计时器调用Audio.Play();但是音乐播10几秒就停了
我也遇到这个问题了,还在解决,而且我关闭程序后音乐还关闭不了