Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MediaPlayer > Seek bar in MediaElemen

Not answered Seek bar in MediaElemen

Feed from this thread
  • Manuel avatar

    Posted on Jan 10, 2012 (permalink)

    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,

    Reply

  • Tina Stancheva Tina Stancheva admin's avatar

    Posted on Jan 13, 2012 (permalink)

    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.
     
    Regards,
    Tina Stancheva
    the Telerik team

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

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Silverlight > MediaPlayer > Seek bar in MediaElemen
Related resources for "Seek bar in MediaElemen"

Silverlight MediaPlayer Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  ]