20 Jun '13 - 12:54 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: [C#] current position for hscrollbar1  (Read 2546 times)
lab82soft
Posts: 10


« on: 3 Apr '08 - 20:44 »
Reply with quoteQuote

Hi,
My problems,
current track time in hscrollbar1.Value

My Code:
private void timerTrack_Tick(object sender, EventArgs e)
        {
            long pos = Bass.BASS_ChannelGetPosition(_stream); // position in bytes
            long len = Bass.BASS_ChannelGetLength(_stream); // length in bytes
            _tickCounter++;
            if (_tickCounter == 5)
{
// display the position every 250ms (since timer is 50ms)
_tickCounter = 0;
                double totaltime = Bass.BASS_ChannelBytes2Seconds(_stream, len); // the total time length
                double elapsedtime = Bass.BASS_ChannelBytes2Seconds(_stream, pos); // the elapsed time length
                double remainingtime = totaltime - elapsedtime;
                //statusBar1.Text = String.Format("Elapsed: {0:#0.00} - Total: {1:#0.00} - Remain: {2:#0.00}", Utils.FixTimespan(elapsedtime, "MMSS"), Utils.FixTimespan(totaltime, "MMSS"), Utils.FixTimespan(remainingtime, "MMSS"));

                this.textBox2.Text = String.Format("{0:#0.00}", Utils.FixTimespan(elapsedtime, "MMSS"));

                this.textBox3.Text = String.Format("{0:#0.00}", Utils.FixTimespan(totaltime, "MMSS"));

                //this.TxtRemain.Text = String.Format("Remain: {0:#0.00}", Utils.FixTimespan(remainingtime, "MMSS"));
ERRORE:--->>   this.hScrollBar1.Value = pos;
}     
        }

Impossible convert to method long in int.

solution?.

thanks!
Logged
radio42
Posts: 4030


« Reply #1 on: 3 Apr '08 - 21:02 »
Reply with quoteQuote

A "scrollBar.Value" is defined as an int (4-bytes).
Whereas "pos" is defined as a long (8-byte).
So of course you can not simply assign a long value to an int value.

The solution is:
a) simply cast it to an int: scrollBar.Value = (int)pos;
-> downside: you scrollbar can not cover files with a length greater than int.MaxValue bytes!

b) scale by some factor: scrollBar.Value = (int)(pos / 10L);
-> downside you are loosing precision, as when moving the scrollBar you would convert it back like:
    pos = scrollBar.Value * 10L;

c) write your own UI control which can handle long values ;-)
Logged
lab82soft
Posts: 10


« Reply #2 on: 3 Apr '08 - 21:06 »
Reply with quoteQuote

ok,
my problem in hscrollbar1 for seek position track time on play.

Post immage: Forms controls.

Solution?.

* hscrollbar1.jpg (4.75 KB - downloaded 40 times.)
Logged
lab82soft
Posts: 10


« Reply #3 on: 4 Apr '08 - 10:35 »
Reply with quoteQuote

up?

solution?
Logged
radio42
Posts: 4030


« Reply #4 on: 4 Apr '08 - 11:27 »
Reply with quoteQuote

Have you read my post above?
Logged
lab82soft
Posts: 10


« Reply #5 on: 4 Apr '08 - 15:24 »
Reply with quoteQuote

Yes I read, now works. Then I say why not work so well HScrollbar, moving from left to right. What should I put the maximum and minimum,
To make it work well.

thanks.
Logged
lab82soft
Posts: 10


« Reply #6 on: 4 Apr '08 - 16:52 »
Reply with quoteQuote

Hello, you have a solution?.
Thanks.
Logged
BassFan
Guest
« Reply #7 on: 4 Apr '08 - 17:08 »
Reply with quoteQuote

Hello, you have a solution?.
Thanks.

hmmmm

private float StreamPos;

// get stream position from bass
StreamPos = Convert.ToSingle(Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream, BASSMode.BASS_POS_BYTES)));

ok now use StreamPos with the Value of hScrollBar1

how you can get the time for a label

// format position HH:MM:SS write in to lblTime
lblTime.Text = GetTime((int)(Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream, BASSMode.BASS_POS_BYTES))));

#region GetTime()

public string GetTime(int seconds)
{
    string returnValue;

    float hour;
    float min;
    float sec;

    hour = seconds / 3600;
    sec = seconds % 60;
    min = seconds / 60;

    returnValue = string.Format("{0:00}:{1:00}:{2:00}", (int)hour, (int)min, (int)sec);

    return returnValue;
}

#endregion GetTime()

greets BassFan
« Last Edit: 4 Apr '08 - 17:17 by BassFan » Logged
lab82soft
Posts: 10


« Reply #8 on: 4 Apr '08 - 17:29 »
Reply with quoteQuote

Hi,

I Read post above. no problems.

My problems to created my bar progess , like :

thanks.


* hscrollbar.jpg (7.83 KB - downloaded 21 times.)
Logged
BassFan
Guest
« Reply #9 on: 4 Apr '08 - 17:36 »
Reply with quoteQuote

Hi,

I Read post above. no problems.

My problems to created my bar progess , like :

thanks.



not understand what you mean .. sorry

greets BassFan
Logged
BassFan
Guest
« Reply #10 on: 4 Apr '08 - 17:51 »
Reply with quoteQuote

think you mean!! hmmm

// get stream position from bass
StreamPos = Convert.ToSingle(Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetPosition(Stream, BASSMode.BASS_POS_BYTES)));

// get stream length from bass
StreamLength = Convert.ToSingle(Bass.BASS_ChannelBytes2Seconds(Stream, Bass.BASS_ChannelGetLength(Stream, BASSMode.BASS_POS_BYTES)));

you have now 2 variable work with it on MAXHSCROLL(VALUE)

greets BassFan
Logged
lab82soft
Posts: 10


« Reply #11 on: 4 Apr '08 - 18:21 »
Reply with quoteQuote

ok,
       hScrollBar1.Maximum = (int)len;
       hScrollBar1.Value = (int)pos;
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines