[英]C# Mediaplayer doesn't play mp3 file from resources
Mediaplayer didn't work for me, so I moved to a simple test project (C# Console App). Mediaplayer对我不起作用,因此我转到了一个简单的测试项目(C#控制台应用程序)。 I added my .mp3 file to the project like this:
我将我的.mp3文件添加到项目中,如下所示:
Sadly, this code doesnt work: 可悲的是,这段代码不起作用:
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();
}
}
}
However, this one does: 但是,此功能可以:
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();
}
}
}
Any idea about what is wrong? 有什么不对的想法吗?
You cannot use MediaPlayer
from a internal exe/dll resource. 您不能从内部exe / dll资源使用
MediaPlayer
。 You should choose another player component or write it to disk. 您应该选择另一个播放器组件或将其写入磁盘。 If you can choose another player, looks like
System.Media.SoundPlayer
could do the trick. 如果您可以选择其他播放器,则
System.Media.SoundPlayer
可以解决问题。 Search for stack overflow Play wav/mp3 from memory
there should give some results 搜索堆栈溢出
Play wav/mp3 from memory
应该会给出一些结果
What about this: 那这个呢:
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.