I have written a simple application that plays a video file in one window and duplicate the video frames to the second window (syncron video rendering). It works fine as long as both windows are on the same monitor. If I move one window to another monitor and resize it, the video lacks. This is my code:
XAML container in both windows:
<Grid>
<Viewbox Stretch="Uniform">
<Rectangle Name="rectVideo">
<Rectangle.Fill>
<DrawingBrush>
<DrawingBrush.Drawing>
<VideoDrawing x:Name="aVideoDrawing" Rect="0,0,10,10" />
</DrawingBrush.Drawing>
</DrawingBrush>
</Rectangle.Fill>
</Rectangle>
</Viewbox>
</Grid>
Code behind of the first window:
public partial class MainWindow : Window
{
MediaPlayer mplayer = new MediaPlayer();
Renderer rnd = new Renderer();
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
mplayer.Open(new Uri("test.mp4", UriKind.Relative));
mplayer.MediaOpened += Mplayer_MediaOpened;
}
private void Mplayer_MediaOpened(object sender, EventArgs e)
{
rectVideo.Height = mplayer.NaturalVideoHeight;
rectVideo.Width = mplayer.NaturalVideoWidth;
aVideoDrawing.Player = mplayer;
rnd.SetPlayer(mplayer);
rnd.Show();
mplayer.Play();
}
}
Code behind the second window:
public partial class Renderer : Window
{
public Renderer()
{
InitializeComponent();
}
public void SetPlayer(MediaPlayer mp)
{
rectVideo.Height = mp.NaturalVideoHeight;
rectVideo.Width = mp.NaturalVideoWidth;
aVideoDrawing.Player = mp;
}
}
Any ideas what could be the problem? I tried it on many different windows systems also with different video cards (e.g. NVidia GTX 1050 Ti, Intel HD 6000 ...) with the same problem. Why does this issue only happen when working with a second monitor?
Update: This question has been already asked here. There is currently no simple and clean solution.