views:

283

answers:

2

I'm making a media player in wpf using c#. I had 3 questions.

  1. I tried making a seeker

    XAML:

    <Slider Name="timelineSlider" Margin="40,91,26,0" ValueChanged="SeekToMediaPosition" Height="32" VerticalAlignment="Top" />
    

    Code:

    private void Element_MediaOpened(object sender, EventArgs e)
    {
        timelineSlider.Maximum = ply.NaturalDuration.TimeSpan.TotalMilliseconds;
    }
    
    
    private void SeekToMediaPosition(object sender, RoutedPropertyChangedEventArgs<double> e)
    {
        int SliderValue = (int)timelineSlider.Value;
        TimeSpan ts = new TimeSpan(SliderValue, SliderValue, SliderValue, SliderValue, SliderValue);
        ply.Position = ts;
    }
    

    When I run the program, I open the mp3 and play it but the seeker won't move. When I click on the seeker to move it to a certain position, the song stops playing but the seeker moves. What's the problem and how do I fix it?

  2. How do I create a volume increase/decrease bar?

  3. How can I open several mp3s and queue them up like a playlist?

A: 

Answer to #2 you will need to keep a ordered collection of files to play, and listen to mediaStopped event, and play the next file in the collection.

LnDCobra
A: 

I am going to assume that you are playing the MP3 using the MediaElement control? If so your seeker (sometimes called a scrubber) can bind to the Position property of the MediaElement.

<MediaElement x:Name="_media"  />
<Slider Name="timelineSlider" 
        Margin="40,91,26,0" 
        Height="32" 
        VerticalAlignment="Top"
        Value="{Binding Path=Position.TotalMilliseconds, Mode=TwoWay, ElementName=_media}" />

If you want to create volume slider you can use a similar method by binding to the Volume Property, per the MSDN document the volume is a value between 0 and 1.

<Slider Name="_volumeSlider"
        Minimum="0"
        Maximum="1"
        Value="{Binding Path=Volume, Mode=TwoWay, ElementName=_media}" />

Regarding playing multiple files you'll want to adopt an approach similar to what LnDCobra indicated in their answer.

Richard C. McGuire