我正在使用MediaElement播放视频。为了获得所选视频的总持续时间,我使用的是MediaOpened事件。现在我想在每10秒的视频上显示一个文本。怎么可能?播放视频时有什么事吗?
<Button Content="Select Video" HorizontalAlignment="Stretch" Click="Button_Click"/>
<MediaElement Name="videoMediaElement" MediaOpened="videoMediaElement_MediaOpened" />
<TextBlock x:Name="tb_display_roadname" TextWrapping="Wrap" />
private async void videoMediaElement_MediaOpened(object sender, RoutedEventArgs e)
{
// bool isLive = IsLiveStream(sender as MediaElement);
var totalDurationTime = videoMediaElement.NaturalDuration.TimeSpan.TotalSeconds;
}
private async void Button_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
foreach (string extension in FileExtensions.Video)
{
openPicker.FileTypeFilter.Add(extension);
}
file = await openPicker.PickSingleFileAsync();
// mediaPlayer is a MediaElement defined in XAML
if (file != null)
{
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
videoMediaElement.SetSource(stream, file.ContentType);
}
}