Seek bar in MediaElemen

2 posts, 0 answers
  1. Manuel
    Manuel avatar
    61 posts
    Member since:
    Oct 2011

    Posted 10 Jan 2012 Link to this post

    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()
                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)
                    Slider1.Maximum = MediaEl.NaturalDuration.TimeSpan.TotalMinutes;

     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);

    My seek bar doesn´t work and i don´t know why.

    Any help please..

    Thanks in advance,
  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 13 Jan 2012 Link to this post

    Hi Manuel,

    From your code snippets it seems you're not using the RadMediaPlayer control but you're rather trying to create a custom media player control.

    This is why I wanted to ask you if you can use the RadMediaPlyer control in this scenario - the control has a built-in timeline that shows the length of the played media and indicates the progress of the video. This is why if you use the RadMediaPlayer control you won't have to create a RadSlider control to display the current progress of the media, neither a TextBlock displaying the elapsed time.
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top