Hi there,
I created a MediaPlayer using MediaElement, but I´ve a problems creating seek bar. I can´t sincronize my seek bar with player.
Here is my code:
public ReunioesAudio()
{
InitializeComponent();
MediaEl.Loaded += new RoutedEventHandler(MediaEl_Loaded);
MediaEl.CurrentStateChanged += new RoutedEventHandler(MediaEl_CurrentStateChanged);
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(50);//500
timer.Tick+=new EventHandler(timer_Tick);
}
void MediaEl_CurrentStateChanged(object sender, RoutedEventArgs e)
{
if (MediaEl.CurrentState == MediaElementState.Playing)
{
timer.Start();
Slider1.Maximum = MediaEl.NaturalDuration.TimeSpan.TotalMinutes;
}
else
{
timer.Stop();
}
}
private void timer_Tick(object sender, EventArgs e)
{
if (MediaEl.NaturalDuration.TimeSpan.TotalSeconds > 0 && !VideoBloqueado)
{
txtVideoPosition.Text = MediaEl.Position.Minutes + ":" + MediaEl.Position.Seconds;
this.Slider1.Value = this.MediaEl.Position.TotalSeconds / MediaEl.NaturalDuration.TimeSpan.TotalSeconds;
}
}
double percent;
private void Slider1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
VideoBloqueado = true;
}
private void Slider1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
VideoBloqueado = false;
MediaEl.Position = TimeSpan.FromSeconds(Slider1.Value);
}
private void MediaEl_MediaOpened(object sender, RoutedEventArgs e)
{
if (MediaEl.NaturalDuration.HasTimeSpan)
{
TimeSpan ts = MediaEl.NaturalDuration.TimeSpan;
//Slider1.LargeChange = Math.Min(10, ts.Seconds / 10);
}
//MediaEl.Play();
}
My seek bar doesn´t work and i don´t know why.
Any help please..
Thanks in advance,
I created a MediaPlayer using MediaElement, but I´ve a problems creating seek bar. I can´t sincronize my seek bar with player.
Here is my code:
public ReunioesAudio()
{
InitializeComponent();
MediaEl.Loaded += new RoutedEventHandler(MediaEl_Loaded);
MediaEl.CurrentStateChanged += new RoutedEventHandler(MediaEl_CurrentStateChanged);
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(50);//500
timer.Tick+=new EventHandler(timer_Tick);
}
void MediaEl_CurrentStateChanged(object sender, RoutedEventArgs e)
{
if (MediaEl.CurrentState == MediaElementState.Playing)
{
timer.Start();
Slider1.Maximum = MediaEl.NaturalDuration.TimeSpan.TotalMinutes;
}
else
{
timer.Stop();
}
}
private void timer_Tick(object sender, EventArgs e)
{
if (MediaEl.NaturalDuration.TimeSpan.TotalSeconds > 0 && !VideoBloqueado)
{
txtVideoPosition.Text = MediaEl.Position.Minutes + ":" + MediaEl.Position.Seconds;
this.Slider1.Value = this.MediaEl.Position.TotalSeconds / MediaEl.NaturalDuration.TimeSpan.TotalSeconds;
}
}
double percent;
private void Slider1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
VideoBloqueado = true;
}
private void Slider1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
VideoBloqueado = false;
MediaEl.Position = TimeSpan.FromSeconds(Slider1.Value);
}
private void MediaEl_MediaOpened(object sender, RoutedEventArgs e)
{
if (MediaEl.NaturalDuration.HasTimeSpan)
{
TimeSpan ts = MediaEl.NaturalDuration.TimeSpan;
//Slider1.LargeChange = Math.Min(10, ts.Seconds / 10);
}
//MediaEl.Play();
}
My seek bar doesn´t work and i don´t know why.
Any help please..
Thanks in advance,