Click here to Skip to main content
15,886,055 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
Hi,

I am working on media player . I have to keep seekbar for the player. I am using slider . Task is the slider should move with media .But problem is that it is just stuck there and not moving. My code goes here

xaml

HTML
<MediaElement Height="Auto" HorizontalAlignment="Stretch" Margin="-12,-45,0,0" Name="mediaElement1"  CurrentStateChanged="mediaElement1_CurrentStateChanged"
 VerticalAlignment="Stretch" Width="Auto" AutoPlay="True" Loaded="mediaElement1_Loaded" MediaEnded="mediaElement1_MediaEnded" MediaOpened="mediaElement1_MediaOpened" />
            <Slider Name="timelineSlider" Margin="5,348,5,5" ValueChanged="timelineSlider_ValueChanged" />


xaml.cs

HTML
private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {
            timelineSlider.Maximum = mediaElement1.NaturalDuration.TimeSpan.TotalMilliseconds;
        }

        private void timelineSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            int SliderValue = (int)timelineSlider.Value;
            TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
            mediaElement1.Position = ts;
        }


can anyone suggest me solving this...thanks in advance
Posted

1 solution

Hi , first of all i would suggest to add such propertsion to MediaElement declaration

And the question is formed what kind of media did you play ??
Is it a buffered ? or it is just from file ?
According to answer , default media behaviors could be applied

Ok , if it not buffered try to do the next:

XML
<slider x:name="timelineSlider" thumb.dragstarted="seekBar_DragStarted" thumb.dragcompleted="seekBar_DragCompleted">


C#
private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
 {
    TimeSpan ts = mediaElement1.NaturalDuration.TimeSpan;
    timelineSlider.Maximum = ts.TotalSeconds;
    timelineSlider.SmallChange = 1;
    timelineSlider.LargeChange = Math.Min(10, ts.Seconds / 10);
 }


C#
private void seekBar_DragCompleted(object sender, DragCompletedEventArgs e)
{
    mediaElement1.Position = TimeSpan.FromSeconds(timelineSlider.Value);
}
 
Share this answer
 
v5
Comments
Raghavanand 26-Dec-12 5:01am    
playing the video "from the file"
Oleksandr Kulchytskyi 26-Dec-12 5:13am    
Ok , i have updated my solution, so you can look at it, if it will help to U, please accept the solution and mark my answer ;)
Raghavanand 26-Dec-12 5:38am    
it is showing that dragstarted and dragcompleted are not a properties of thumb
Oleksandr Kulchytskyi 26-Dec-12 5:43am    
Which version of WP core ? 7.0 or 7.1??
Raghavanand 26-Dec-12 5:44am    
it is WP 7.1

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900