I want a MediaElement application. I want to pause MediaElement with this application at specified times. Theorically, I should use 2 DispatcherTimer for this. I am using a DispatcherTimer for pause but second timer does not run. Is there any problem with my codes ?Here is my code. Thanks inadvance
static DispatcherTimer dispatcherTimer, dispatcherTimer2;
private void MediaElement_CurrentStateChanged(object sender, RoutedEventArgs e)
{
if (((MediaElement)sender).CurrentState == MediaElementState.Playing)
{
tbMessage.Text = "playing";
dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler<object>(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
dispatcherTimer2 = new DispatcherTimer();
dispatcherTimer2.Tick += dispatcherTimer2_Tick;
dispatcherTimer2.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer2.Start();
}
}
void dispatcherTimer2_Tick(object sender, object e)
{
tb2.Text = dispatcherTimer2.Interval.Seconds.ToString();
if (dispatcherTimer2.Interval.Seconds == 12)
{
mp.Play();
//dispatcherTimer.Start();
}
}
private void dispatcherTimer_Tick(object sender, object e)
{
// Updating the Label which displays the current second
tbMessage.Text = DateTime.Now.Second.ToString();
tbMessage.Text = mp.Position.Seconds.ToString() + " " + dispatcherTimer.Interval.Seconds.ToString();
if (mp.Position.Seconds == 3)
{
mp.Pause();
}
}