Progress bars

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am
Location: Dorset, UK

Progress bars

Post by Damlimey » Thu Jun 04, 2009 5:45 pm

Hi all,

Me again! Can anyone tell me how to script a progress bar so that it will show the progress of an audio track running in an object player?

While I'm here, what about displaying the following: total time of the audio track, time into the track and time remaining?

Thanks in advance for your help with this,

G

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Post by bn » Thu Jun 04, 2009 7:08 pm

G,

make a player object called "p1", make a scrollbar/progressbar call it "sb1" make a field call it "f1" and make a button, call it what you like.

set the script of the button to:

Code: Select all

# make tDuration a script local variable so the 
# adjustScrollbar handler can access it
local tDuration

on mouseUp
   if the filename of player "p1" is  "" then exit mouseUp
   # duration of a player is the the duration in timescale * duration in seconds
   put the duration of player "p1" into tDuration
   put the timescale of player "p1" into tTimeScale
   
   # get the duration in min:sec.fraktion sec
   set the numberformat to "00.##"
   put round (tDuration / tTimeScale,2) into tSeconds
   put round (tSeconds div 3600) into tMinutes
   put tSeconds mod 3600 into tSeconds
   put tMinutes & ":" & tSeconds into field "f1"
   
   # adjust the scrollbar to the duration of the player
   set the endvalue of scrollbar "sb1" to tDuration
   set the thumbposition of scrollbar "sb1" to the currenttime of player "p1"
   
   start player "p1"
   
   # send in time avoids locking up Rev
   send adjustScrollbar to me in 80 milliseconds
   
end mouseUp

on adjustScrollbar
   set the thumbposition of scrollbar "sb1" to the currenttime of player "p1"
   # only invoke this handler again if player is still playing
   if the not the paused of player "p1"  then
      send adjustScrollbar to me in 80 milliseconds
   end if
end adjustScrollbar
from the player you get the duration in seconds * the timescale. The timescale is the measure to determine the fractions of a second for the sound or movie. It is ususally 600 but not necessarily so. With a timescale of 600 you have good control over the time intervals in movies or sounds. That is why it is a little more complicated to get at the Duration in seconds and minutes.
You might want to look that up in the dictionary.
Also the send in time construct might not be familiar to you. But once you realize that a repeat loop would effectively lock up Rev in this repeat loop you see the advantage of the send in time method. It is often useful in Rev if you have time consuming handlers and want Rev to be still responsive to e.g. user input.
Anyway this should get you started
regards
Bernd

Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am
Location: Dorset, UK

Thank you for that

Post by Damlimey » Fri Jun 05, 2009 3:40 pm

Hi Bernd,

Thank you for that, it has got me started. Incidentally, by modifying your script thus:

set the numberformat to "00.##"
put round (tDuration / tTimeScale) into tSeconds
put round (tSeconds div 60) into tMinutes
put tSeconds mod 60 into tSeconds
put tMinutes & ":" & tSeconds into field "f1"

The field displayed the correct minutes and seconds (fractions not required).

I am very grateful for your help as I am starting from nowhere as far as programming experience is concerned but I know what I am trying to achieve and you are being a great help.

G

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Sat Jun 06, 2009 12:02 pm

HI G,

I once created a function that you might use:

Code: Select all

function smpte_lite tTime
  set the numberformat to xx
  put tTime div 60 into minu
  put tTime mod 60 into seku
  return minu & ":" & seku
end smpte_lite
You can the use it to get the current and remaining time with:
...
put round(the currenttime of player "XXX"/the timescale of player "XXX") into tNOW
put smpte_lite(tNOW) into field "currenttime"

put round(the duration of player "XXX"/the timescale of player "XXX") into tTotal
put round(tTotal - tNOW) into tRemainig
put smpte_lite(tRemainig) into fld "remaining_time"
...

You get the picture :-)


Best

Klaus

Damlimey
Posts: 31
Joined: Sun May 31, 2009 10:56 am
Location: Dorset, UK

The smpte function

Post by Damlimey » Sun Jun 07, 2009 9:40 am

Hi Klaus,

Thank you for that, I assume that I can place that code in the appropriate field scripts?

I'll try it there first anyway!

G

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Post by Klaus » Sun Jun 07, 2009 11:30 am

Hi G,

I put this into the stack script so I can use it with every button/player
on all cards of this stack and its substacks :-)


Best

Klaus

Remog
Posts: 4
Joined: Tue Jun 04, 2013 9:09 pm

Re: Progress bars

Post by Remog » Wed Jun 05, 2013 2:16 pm

Sorry to bump such an old post, but this has been helping me quite a bit.

I have all this working, but I would also like to have "f1" count down the remaining minutes:seconds in the track that is playing. I see the "f1" is being updated at the beginning with the length of the song, but it doesn't count down.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Progress bars

Post by Klaus » Wed Jun 05, 2013 2:41 pm

Hi Remog,

total time - CurrentTime = Remaining time!
Does that help?

I will delete your "Question regarding Media files" thread, if you don't mind...


Best

Klaus

Remog
Posts: 4
Joined: Tue Jun 04, 2013 9:09 pm

Re: Progress bars

Post by Remog » Wed Jun 05, 2013 5:44 pm

I get the math, however, I cannot seem to get the field to update continuously, it throws errors when I loop it in with the progress bar updates.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Progress bars

Post by Klaus » Wed Jun 05, 2013 6:44 pm

Hi Remog,

ah, sorry, misunderstood your question.
Well take a deeper look at my first example script, the trick is to "SEND" the handler that updates the field continously in intervals < 1 seconds.

Ther are no automatisms for this in Livecode, so you need to do it yourself.

Code: Select all

# make tDuration a script local variable so the 
# adjustScrollbar handler can access it
local tDuration

on mouseUp
   if the filename of player "p1" is  "" then 
      exit mouseUp
  end if
   # duration of a player is the the duration in timescale * duration in seconds
   put the duration of player "p1" into tDuration
   put the timescale of player "p1" into tTimeScale
   
   # get the duration in min:sec.fraktion sec
   set the numberformat to "00.##"
   put round (tDuration / tTimeScale,2) into tSeconds
   put round (tSeconds div 3600) into tMinutes
   put tSeconds mod 3600 into tSeconds
   put tMinutes & ":" & tSeconds into field "f1"
   
   # adjust the scrollbar to the duration of the player
   set the endvalue of scrollbar "sb1" to tDuration
   set the thumbposition of scrollbar "sb1" to the currenttime of player "p1"
   
   start player "p1"
   
   # send in time avoids locking up Rev
   send adjustScrollbar to me in 100 milliseconds
   
end mouseUp
on adjustScrollbar
   set the thumbposition of scrollbar "sb1" to the currenttime of player "p1"
   # only invoke this handler again if player is still playing
   if the not the paused of player "p1"  then
      send "adjustScrollbar" to me in 100 milliseconds
   end if
end adjustScrollbar
Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Progress bars

Post by bn » Wed Jun 05, 2013 6:58 pm

Hi Remog,

here is a stack that does what you want. It uses basically the script that I posted above. Note I changed some of the variable names to reflect that they are script local variables.

Kind regards
Bernd
Attachments
showProgressOfPlayer.livecode.zip
(1.7 KiB) Downloaded 423 times

gwin
Posts: 3
Joined: Fri Mar 06, 2015 10:23 am

Re: Progress bars

Post by gwin » Sat Mar 07, 2015 3:45 am

This script has helped me a lot but I am failing to make it work on iOS.

I am substituting lines of code as follows;

For duration, this seems to be correct (or maybe I should use playableDuration)

Code: Select all

//put the duration of player "p1" into sDuration
put mobileControlGet ("myPlayer","duration") into sDuration
but I cannot find an equivalent for timescale...

Code: Select all

 //put the timescale of player "p1" into sTimeScale
 put mobileControlGet ("myPlayer","????????") into sTimeScale
and for currentTime I guess I can use the following line...

Code: Select all

//put round ((sDuration - the currentTime of player "p1")/ sTimeScale,2) into tSeconds
put round ((sDuration - mobileControlGet ("myPlayer","currentTime") )/ sTimeScale,2) into tSeconds
   
Any ideas? Thank you.

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Progress bars

Post by Klaus » Sat Mar 07, 2015 12:41 pm

Trying to re-vive an old an DEAD thread is not a good idea, you already have a thread for your problem 8)

Post Reply

Return to “Multimedia”