[英]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.