To show user that the video has ended in WPF
I need help! I'm facing a problem that is got to do with Slider + Tree View + Video. Using Blend and WPF, language C#.
Header
(a) sub header X << Play Video (a) only on click
(b) sub header Y << Play Video (b) only on click
Video (a) [Duration 0:00 to 0:09] and Video (b) [Duration 0:10 to 0:20]
I have combined the Video (a) and Video (b) into one video, so that when user click either (a) sub header X or (b) sub header Y, it will play on that particular Video and the slider also can detect where's the Video.
So now, I want to like stop the video when user click on (a) sub header X, after playing finish the Video (a), it will prompt the user to click on the (b) sub header Y to continue watching the video.
If I don't want prompt, I can also just write some texts on the Textbox to show user that the Video (a) has ended, and now they are watching the Video (b) part.
My coding are shown below:
private void headerX_Selected(object sender, RoutedEventArgs e)
{
Video.Source = new Uri(@".\cooking.wmv", UriKind.Relative);
开发者_C百科
Video.Play();
info.Text = "Boil 500ml of water.";
}
private void headerY_Selected(object sender, RoutedEventArgs e)
{
Video.Position = TimeSpan.FromSeconds(VideoTime.Value = 10);
Video.Play();
info.Text = "Add noodles when the water has boiled.";
}
- Video = the MediaElement
- VideoTime = the name of the slider
- cooking.wmv = the Video
- info.Text = Textbox
Any help would be appreciated.
From what I have gathered, then this is basically what you need to do:
- You need to figure out when video/clip (a) has finished. You could perhaps wire up an event to slider.ValueChanged (
VideoTime.ValueChanged
in your case) and check if value is slider.MaxValue. Or you could create a timer that fires a tick after clip (a) duration. - Once the first point has been tackled with, then the rest should be easy. Assuming you have a checkbox for whether to prompt or simply show some text, at the point where you detect that clip (a) has finished, you check the state of the checkbox and act accordingly - either stop/pause the video (
Video.Stop();
) and show a prompt or write something into a textbox...
PS! I'm writing off the top of my head, I haven't verified that the slider control has a ValueChanged event (I assume it does), etc...
精彩评论