[英]C# Mediaplayer doesn't play mp3 file from resources
Mediaplayer對我不起作用,因此我轉到了一個簡單的測試項目(C#控制台應用程序)。 我將我的.mp3文件添加到項目中,如下所示:
可悲的是,這段代碼不起作用:
namespace test
{
class Program
{
public static void Main(string[] args)
{
MediaPlayer player = new MediaPlayer();
player.Open(new Uri("resources/warn.mp3", UriKind.Relative));
player.Play();
Console.ReadKey();
}
}
}
但是,此功能可以:
namespace test
{
class Program
{
public static void Main(string[] args)
{
MediaPlayer player = new MediaPlayer();
player.Open(new Uri("C:\\Users\\Krepsy3\\Documents\\Programs\\OOP\\test\\test\\resources\\warn.mp3", UriKind.Absolute));
player.Play();
Console.ReadKey();
}
}
}
有什么不對的想法嗎?
您不能從內部exe / dll資源使用MediaPlayer
。 您應該選擇另一個播放器組件或將其寫入磁盤。 如果您可以選擇其他播放器,則System.Media.SoundPlayer
可以解決問題。 搜索堆棧溢出Play wav/mp3 from memory
應該會給出一些結果
那這個呢:
namespace test
{
class Program
{
public static void Main(string[] args)
{
MediaPlayer player = new MediaPlayer();
player.Open(new Uri(System.Environment.CurrentDirectory + "\resources\warn.mp3", UriKind.Relative));
player.Play();
Console.ReadKey();
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.