Mads Andersen
Mads Andersen

Reputation: 3153

Playing mp3 in WPF

MediaElement doesnt work for me in my WPF application.

mediaElement1.LoadedBehavior = MediaState.Manual;
mediaElement1.Source = new Uri(@"C:\Music\MySong.mp3", UriKind.RelativeOrAbsolute);
mediaElement1.Play();

When I do this in my Window1.xaml.cs file. Nothing happens. Atleast I cant hear anything. I have tried all kind of different things, but no sound.

In winforms:

axWindowsMediaPlayer1.URL = @"C:\Music\MySong.mp3";
axWindowsMediaPlayer1.Ctlcontrols.play();

Works without any problems. Any simple solution or things to try?

Upvotes: 4

Views: 14001

Answers (3)

mediaElement1.LoadedBehavior = MediaState.Manual; ---- edit to----- mediaElement1.LoadedBehavior = System.Windows.Controls.MediaState.Manual;

Upvotes: 0

abhishek verma
abhishek verma

Reputation: 11

Though I'm also new in wpf,One thing you should notice about media element is that providing source in the XAML tag is not worth working. you need to provide the source with the urikind like this

media.Source = new Uri(@"E:\Pehli_Baar_Mohabbat.mp3",UriKind.RelativeOrAbsolute);

put this line in window constructor

and set loadedbehavious=manual and then check.

Upvotes: 1

Mads Andersen
Mads Andersen

Reputation: 3153

Ok I solved it. WPF only support MediaElement if you have Windows Media Player 10 or above. I was running WMP9.

Upvotes: 6

Related Questions