Play mp3 in WPF

MediaElement does not 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 happened. At least I don’t hear anything. I tried all kinds of things, but without sound.

In winforms:

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

It works without problems. Any simple solution or something to try?

+3
source share
3 answers

Ok, I decided. WPF only supports MediaElement if you have Windows Media Player 10 or higher. I ran WMP9.

+6
source

wpf, - , XAML . urikind,

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

loadedbehavious=manual, .

+1

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

0
source

Source: https://habr.com/ru/post/1721494/


All Articles