Click here to Skip to main content
14,362,267 members
Rate this:
Please Sign up or sign in to vote.
I'm working in an audio player based on C#
The player component I use is made with the CSCore open-source library.

I have a circular slider control which has a ProgressValue property based in an Integer.

When I play a song, the slider's max value is set to the song's totalSeconds length, and a timer is started.

In the timer Tick Event, the slider value changes according to the actual song's position (Which is a Timespan as the Length too).

I want to be able to change the song's position when I change the slider's value with my mouse.

Now, the value changes, but when I reléase the mouse from the control, the media starts again from the beginning. I don't get any errors, exceptions, etc. The application just keeps running normally. The code simply doesn't work correctly.

Here's my piece of code in the ValueChanged Event Handler of the Circular Slider control:

private void songProgress_ValueChanged(object sender, ValueChangedEventArgs e)
       {
               TimeSpan newPosition = new TimeSpan();
               newPosition.Add(TimeSpan.FromSeconds(songProgress.ProgressValue));
               player.Position = newPosition;

       }


Here's the link to the player component code: https://raw.githubusercontent.com/filoe/cscore/master/Samples/AudioPlayerSample/MusicPlayer.cs[^]
And here's the link to the complete library: https://github.com/filoe/cscore[^]

[EDIT] Got this second approach with no success:
private void songProgress_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            TimeSpan ts = TimeSpan.FromSeconds(e.NewValue);
            player.Position = ts;
        }


Hope someone helps me. Thanks in Advance - CCB
Posted
Updated 15-Nov-15 15:47pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

First of all you could probably get a better answer here https://github.com/filoe/cscore/issues[^]

When it comes to your code snippet you can simplify like this
private void songProgress_ValueChanged(object sender, ValueChangedEventArgs e)
{
    player.Position = TimeSpan.FromSeconds(songProgress.ProgressValue);
}

Then you put a break-point at this line and check the value of player.Position before and after execution of the line.

[UPDATE]
As you have the source code for the player you can debug into that code too.
public TimeSpan Position
{
    get
    {
        if (_waveSource != null)
            return _waveSource.GetPosition();
        return TimeSpan.Zero;
    }
    set
    {
        if (_waveSource != null)
            _waveSource.SetPosition(value);
    }
}

I guess you have to dig into IWaveSource.SetPosition as well to see what happens there.
The only other thing I can think of is that the slider control is behaving strangely, but that seems unlikely.
Also check if you have any event going on when you release the mouse.
   
v2
Comments
ChrisCreateBoss 15-Nov-15 20:54pm
   
Already tried that but this time, the slider always comes back to second #6.
George Jonsson 15-Nov-15 22:57pm
   
By second #6 I suppose you mean 6 seconds from the start of the song?
That is weird and I have no idea what is causing that. I can only give general trouble shooting help.
See my updated question.
ChrisCreateBoss 16-Nov-15 13:26pm
   
Found the problem. It was not the player's problem, in the Timer Tick I had songProgress.ProgressValue = player.Position.Seconds;
I just changed it to ...player.Position.TotalSeconds; now it works perfect. Thanks for your help!!
George Jonsson 16-Nov-15 18:35pm
   
There is always a good reason for the problem.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100