我正在尝试在测试代码中的特定位置暂停视频,并尝试从完全不同的位置开始播放。它最终确实从另一个点开始,但是当它再次暂停时,它会回到它注册的第一个实例。我想知道我在这段代码中做错了什么。
CS文件中的代码是
namespace timer_thread_and_gui
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
DispatcherTimer timer;
DispatcherTimer timer1;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
timer1 = new DispatcherTimer();
timer1.Tick += new EventHandler(dispatcherTimer_Tick1);
timer1.Interval = new TimeSpan(0, 0, 10);
timer = new DispatcherTimer();
timer.Tick += new EventHandler(dispatcherTimer_Tick);
timer.Interval = new TimeSpan(0, 0, 5);
video_panel.Play();
timer1.Start();
timer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
this.draw_an_elipse();
draw_an_elipse()
{
++a;
txt.Text = a.ToString();
if (a%5==0)
{
video_panel.Stop();
video_panel.Position = new TimeSpan(0, 18, 30);
video_panel.Play();
timer1.Start();
}
}
private void dispatcherTimer_Tick1(object sender, EventArgs e)
{
video_panel.Pause();
timer1.Stop();
}
}
XAML 代码是
<MediaElement Height="266" HorizontalAlignment="Left" Margin="12,33,0,0" Name="video_panel"
VerticalAlignment="Top" Width="474"
LoadedBehavior="Manual" UnloadedBehavior="Stop"
Source="c:\users\ayymmoo\documents\visual studio 2010\Projects\Unfinished.avi" />