I am having trouble getting videos to play using the WPF MediaElement on a windows 8 box. Since the MediaElement control relies on Windows Media Player, I tried to play the video on my Win 8 box in WMP and it plays fine, so it doesnt appear to be a codec problem. My current theory is it has something to do with WMP, rather than a change I need to make to the code. Any help would be greatly appreciated!
Here is a test app that I mocked up that also has the problem; it works just fine on windows 7 (loads a black screen that plays when you click it), but fails to do anything in win 8 (white screen with no interaction). I've tried several different methods of loading the video in before I concluded it probably didn't matter how I did it, this code is just the last revision. If you want to see the issue yourself (actually, just knowing if its just my windows 8 machine would be very helpful), its a pretty small WPF app and any WMV should work.
C#:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
bool opened = false;
var mre = new ManualResetEvent(false);
currentMediaElement.BeginInit();
currentMediaElement.Source = new Uri("Video.wmv", UriKind.RelativeOrAbsolute);
currentMediaElement.EndInit();
currentMediaElement.LoadedBehavior = currentMediaElement.UnloadedBehavior = MediaState.Manual;
currentMediaElement.MediaOpened += delegate
{
opened = true;
mre.Set();
};
currentMediaElement.Stop();
mre.WaitOne(5000);
}
private void currentMediaElement_MouseDown(object sender, MouseButtonEventArgs e)
{
currentMediaElement.Play();
}
}
XAML:
<Window x:Class="TestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<MediaElement Name="currentMediaElement" MouseDown="currentMediaElement_MouseDown"></MediaElement>
</Grid>
</Window>
Turns out it was either the windows 8 image my company was using or the fact that they were using remote desktop connections to test. If you're running into this issue I recommend trying to change the test environment!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With