I don't see you actually add the Visual to the UI. It's just created and run in the code-behind.
Updated Answer:
MediaPlayer player = new MediaPlayer();
public Window1() {
InitializeComponent();
player.Open(new Uri("airplane.mpg", UriKind.Relative));
VideoDrawing drawing = new VideoDrawing {Rect = new Rect(0, 0, 800, 600), Player = player};
player.Play();
DrawingBrush brush = new DrawingBrush(drawing);
Background = brush;
player.MediaOpened += (sender, args) => MouseMove += OnMouseMove;
player.MediaEnded += (sender, args) => {
MouseMove -= OnMouseMove;
Close();
};
}
private void OnMouseMove(object sender, MouseEventArgs mouseEventArgs) {
player.Stop();
Close();
}
Update:
Another Update:
So the issue was also with having the MouseMove
event firing too soon. Switching it to only capture MouseEvents
after the MediaOpened
event sorts that issue out.