当前位置:编程学习 > C#/ASP.NET >>

WPF中MediaElement控件

我想实现一个播放用户指定音乐的功能,并且把用户播放的音频文件上传到指定的文件名(File.Copy(原文件,目标文件,true))。MediaElement.Source=目标文件路径;

当MediaElement没有使用资源(MediaElement不是处于Play状态时),可以实现文件的复制。

可是MediaElement处于Play状态时,程序讲我目标文件被占用(在执行File.Copy(....)时)。

meWavePlay.Close();
File.Copy(op.FileName, path, true);
meWavePlay.Source = new Uri(path);
meWavePlay.Play();

不知道有什么方法可以实现,我前面学习了Image控件独占资源是这样处理的。
 // Read byte[] from png file
 BinaryReader binReader = new BinaryReader(File.Open(op.FileName, FileMode.Open));
 FileInfo fileInfo = new FileInfo(op.FileName);
 byte[] bytes = binReader.ReadBytes((int)fileInfo.Length);
 binReader.Close();
// Init bitmap
  BitmapImage bitmap = new BitmapImage();
  bitmap.BeginInit();
  bitmap.StreamSource = new MemoryStream(bytes);
  bitmap.EndInit();

  File.Copy(op.FileName, path, true);
  igOne.Source = bitmap; WPF中MediaElement控件 WPF --------------------编程问答-------------------- 怎么没有人帮我解答
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,