This is a migrated thread and some comments may be shown as answers.

Seek bar in MediaElemen

1 Answer 42 Views
MediaPlayer
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 10 Jan 2012, 03:37 PM
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,

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 13 Jan 2012, 01:34 PM
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 >>

Tags
MediaPlayer
Asked by
Manuel
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or