I have two MediaElements to play two videos at a time. For that I have to wait for both to be loaded first. Otherwise, both videos will be played out of sync. To achieve this, I have set two boolean values to true when the MediaOpened event of MediaElement is fired. I want to play the videos once both variables are true. How can I do that?
bool IsOpened1=false;
bool Isopened2=false;
private void btnPlay_Click(object sender, RoutedEventArgs e)
{
if (IsOpened1 == true && IsOpened2== true) //have to wait here until it is true
{
MediaEL.LoadedBehavior = MediaState.Play;
MediaEL2.LoadedBehavior = MediaState.Play;
}
}
private void MediaEL_MediaOpened(object sender, RoutedEventArgs e)
{
Isopened1 = true;
}
private void MediaEL2_MediaOpened(object sender, RoutedEventArgs e)
{
Isopened2 = true;
}
AsyncCountDownEvent(1, 2) for syncronization? You initialize a countdown with 2 and you callSignalwhen a given video is loaded. And in your event handler you are awaiting theWaitAsyncto decrease the countdown to zero.