[英]Play MP3 file from app
我在网上找到了一些代码片段,但问题是它们使用系统本地托管的文件位置,我想从我的应用程序播放MP3或WAV文件并将mp3文件构建到应用程序中,而不是他们需要它以及。可执行程序。 关于如何做这样的事情的任何想法?
嵌入mp3或wav作为资源:
使用以下代码播放它:
WindowsMediaPlayer wmp = new WindowsMediaPlayer();
Stream stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream("yourfile.mp3");
string temppath = Path.GetTempPath() + "\\temp.mp3";
using (Stream output = new FileStream (temppath, FileMode.Create))
{
byte[] buffer = new byte[BUFFER_SIZE];
int read;
while ( (read= stream.Read(buffer, 0, buffer.Length)) > 0)
{
output.Write(buffer, 0, read);
}
}
wmp.URL = temppath;
wmp.controls.play();
完成后,不要忘记删除临时文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.