24 May '13 - 10:12 *
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: time and seconds in c#?  (Read 1822 times)
faggus
Posts: 33


« on: 26 Oct '09 - 13:59 »
Reply with quoteQuote

i'm wondering how to get the length of a track in HH:MM:SS.  i'm using c#, and all the examples i've seen are in vb or delphi.  i'm using the BASS_ChannelBytes2Seconds method and it gives me the seconds in a double, but how do you convert that to minutes and seconds, without a decimal remainder? 

as a side note, how do you bind a trackbar to move to a specific time? 
Logged
faggus
Posts: 33


« Reply #1 on: 26 Oct '09 - 14:09 »
Reply with quoteQuote

after thinking about this, i guess it's too broad.  is there a way to use DateTime() in c# to convert the double to mm:ss?  and how do you guys have your time update itself as a label or text?  do you use a for loop? 
Logged
radio42
Posts: 4012


« Reply #2 on: 26 Oct '09 - 15:43 »
Reply with quoteQuote

You can convert the seconds (as returned by BASS_ChannelBytes2Seconds) to a TimeSpan instance like this:
TimeSpan ts = TimeSpan.FromSeconds(length);

To convert seconds to a DateTime value you must first create a new DateTime instance with no hour/minute/second portion and then add the seconds:
DateTime dt = DateTime.Today;
dt.AddSeconds(length);

You might also want to use the "Utils.FixTimespan" method to convert the seconds to a printable string (see the docs for more info).
Logged
faggus
Posts: 33


« Reply #3 on: 26 Oct '09 - 21:10 »
Reply with quoteQuote

How do you update the text, a loop?  Is there an inherent method that updates it without stealing resources?
Logged
radio42
Posts: 4012


« Reply #4 on: 27 Oct '09 - 06:32 »
Reply with quoteQuote

You can use a timer event to update the text frequently.
Please take a look to the provided samples that come with BASS.NET.
Logged
faggus
Posts: 33


« Reply #5 on: 27 Oct '09 - 21:05 »
Reply with quoteQuote

HoW would you use that with a trackbar slider?  Can you show me an example?
Logged
radio42
Posts: 4012


« Reply #6 on: 27 Oct '09 - 22:10 »
Reply with quoteQuote

Look here: http://www.un4seen.com/forum/?topic=4083.msg27422#msg27422
Or take a look to the provided C# samples.
Logged
faggus
Posts: 33


« Reply #7 on: 30 Oct '09 - 23:50 »
Reply with quoteQuote

yeah, i've seen that thread before, except that it doesn't work for me.  i'm using wpf, and i need to update a label and the trackbar.  could i use dispatchertimer? is there an example around using that?
Logged
radio42
Posts: 4012


« Reply #8 on: 31 Oct '09 - 09:33 »
Reply with quoteQuote

I am not using WPF much, so I don't have any WPF samples available.
Logged
ken
Posts: 630


« Reply #9 on: 31 Oct '09 - 11:33 »
Reply with quoteQuote

yeah, i've seen that thread before, except that it doesn't work for me.  i'm using wpf, and i need to update a label and the trackbar.  could i use dispatchertimer? is there an example around using that?

In WPF you need to use a "DispatcherTimer" for showing position on a label or textbox, otherwise you get threading problems.

http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.aspx

Logged
faggus
Posts: 33


« Reply #10 on: 31 Oct '09 - 18:29 »
Reply with quoteQuote

i got it to work with dispatchertimer.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines