本文介绍了如何从axwindowsmediaplayer发布文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 你好, 我正在使用axwindowsmediaplayer播放一个(tempAudio1.wav)文件,我使用(MakeWavFile)从库中修改(Wave_Constructor)。 br /> 但是当我再次尝试(通过按下负责此按钮的按钮)时,它给了我一个例外,该文件被另一个进程使用,所以我可以'再次修改它。我猜是因为axwindowsmediaplayer没有发布它。 有谁能请给我一个方法从播放器发布文件 使用系统; 使用 System.Collections.Generic; 使用 System.ComponentModel; 使用 System.Data; 使用 System.Drawing; 使用 System.Linq; 使用 System.Text; 使用 System.Windows.Forms; 使用 Wave_Constructor; 使用 System.IO; 命名空间媒体 { public partial class Form1:Form { private void button1_Click( object sender,EventArgs e) { // byte [] tempBuff = new byte [8000 * 60]; //这应该是创建或修改wav文件 string path = Directory.GetCurrentDirectory()+ \\tempAudio1.wav; axWindowsMediaPlayer1.mediaCollection.getAll()。clear(); // WaveConstructor wav = new WaveConstructor(tempBuff.Length); using (FileStream fs = File.Open(path,FileMode.Open)){} // wav.MakeWaveFile(tempBuff,path); axWindowsMediaPlayer1.URL = path; axWindowsMediaPlayer1.settings.autoStart = true ; } } } 解决方案 来自 AxWindowsMediaPlayer对象(VB和C#) [ ^ ],我可以看到有一个关闭方法 [ ^ ]专为释放使用过的资源而设计。您可能需要调用此方法。 此外,您对所显示的代码有一些说法: - 要构建文件的路径,存在 Path.Combine [ ^ ]方法,比仅仅进行原始字符串连接更适合使用。 string path = Path.Combine(Directory.GetCurrentDirectory(), tempAudio1.wav ); - 您的使用区块是空的,因此没用。 - 来自 AxWindowsMediaPlayer.URL property [ ^ ],我可以读到这句话: 不要叫这个事件处理程序代码的方法。从事件处理程序调用URL可能会产生意外结果。 我也不知道正确的方法,因为我所指的页面是只是关于这个对象的基本文档,没有关于如何在各种情况下使用它的真实示例。您可能需要搜索一些真实世界的示例并将其弄清楚(我在Visual Basic论坛上找到了一些,但没有一个能够全面了解它)。 祝你好运。问候。 Hello there,I'm using axwindowsmediaplayer to play a (tempAudio1.wav) file which I modify using (MakeWavFile) from library (Wave_Constructor).but when I try to do it again (by pressing the button responsible for this) it gives me an exception that the file is being used by another process so i can't modify it again. I'm guessing it's because the axwindowsmediaplayer didn't release it.can anyone please give me a way to release the file from the playerusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using Wave_Constructor;using System.IO;namespace Media{ public partial class Form1 : Form { private void button1_Click(object sender, EventArgs e) { //byte[] tempBuff = new byte[8000 * 60];//this should be the source for creating or modifying the wav file string path = Directory.GetCurrentDirectory() + "\\tempAudio1.wav"; axWindowsMediaPlayer1.mediaCollection.getAll().clear(); //WaveConstructor wav = new WaveConstructor(tempBuff.Length); using (FileStream fs = File.Open(path, FileMode.Open)) { } //wav.MakeWaveFile(tempBuff, path); axWindowsMediaPlayer1.URL = path; axWindowsMediaPlayer1.settings.autoStart = true; } }} 解决方案 From AxWindowsMediaPlayer Object (VB and C#)[^], I can see that there is a close method[^] especially designed to release used resources. You may need to call this method.Moreover, there are some things to say about the piece of code you showed:- To construct a path to a file, there exists a Path.Combine[^] method, more suitable to use than just doing a raw string concatenation.string path = Path.Combine(Directory.GetCurrentDirectory(), "tempAudio1.wav");- Your using block is empty, thus useless.- From AxWindowsMediaPlayer.URL property[^], I could read this statement:Do not call this method from event handler code. Calling URL from an event handler may yield unexpected results.I don't know the "correct" method to do it, either, as the pages I am referring to are just basic documentation on this object, there are no real examples of how it should be used in various situations. You may have to search for some real-world examples and figure it out (I found some on a Visual Basic forum, but none that gives a full big picture of it).Good luck. Regards. 这篇关于如何从axwindowsmediaplayer发布文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 12:36