Mediaplayer didn't work for me, so I moved to a simple test project (C# Console App). I added my .mp3 file to the project like this:
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. 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. Search for stack overflow Play wav/mp3 from memory
there should give some results
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();
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.