Progress bars
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Progress bars
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
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
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
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:
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
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
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
Thank you for that
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
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
HI G,
I once created a function that you might use:
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
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
...
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
The smpte function
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
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
Re: Progress bars
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.
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.
Re: Progress bars
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
total time - CurrentTime = Remaining time!
Does that help?
I will delete your "Question regarding Media files" thread, if you don't mind...
Best
Klaus
Re: Progress bars
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.
Re: Progress bars
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.
Best
Klaus
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
Klaus
-
- VIP Livecode Opensource Backer
- Posts: 4003
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: Progress bars
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
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
Re: Progress bars
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)
but I cannot find an equivalent for timescale...
and for currentTime I guess I can use the following line...
Any ideas? Thank you.
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
Code: Select all
//put the timescale of player "p1" into sTimeScale
put mobileControlGet ("myPlayer","????????") into sTimeScale
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
Re: Progress bars
Trying to re-vive an old an DEAD thread is not a good idea, you already have a thread for your problem