Click to See Complete Forum and Search --> : Elapsed Time Counter ?
btchwaxfan
07-17-2003, 06:07 PM
Hello,
I am making a player for SWF files. The SWF contains music, and the player lets you play it.
I would like to include a display of how long the song has been playing. When the song is paused, I want the counter to pause, and if the song is rewound to the start, I want the counter to rest to the zero position.
Does anyone have any ideas how I can accomplish this? The SWF with the music is a seperate file and I can not alter it, although I can put variables in it, such as song length.
Thanks !
necromanthus
07-18-2003, 06:44 AM
Impossible,because Flash player can't process sounds.
;)
btchwaxfan
07-18-2003, 07:47 AM
Hello,
I hope its not impossible. Maybe if I restate my question, we can come up with an idea.
Pretend I have three SWF, player.swf, music.swf, digitalcount.swf. Digitalcount.swf is a simple display of hh:mm:ss. I _could_ set Digitalcount.swf to start at all zeros and incriment one at a second (though I'm not sure how, but I think the ActionScript you gave me before would let me do it.) up to 2 hours (for example's sake). Then, I could have the player load both Digitalcount and music.swf, and play both. It would then appear that the counter is displaying the elapsed time of the song.
However, this is very unelegent, and I just don't see how to make it sync properly. Someone told me that SWF don't always play at the right speed? or maybe one may play slower than it should?
I thought maybe I could make a sprite and tell it to count the number of frames that have passed in music.swf and then divide that by the number of frames per second, but I don't know how to do that, or if its possible (I would guess ActionScript, but that's a guess).
I hope this maybe makes my problem clearer, or inspire an idea? I can create a variable in the music.swf that holds the number of seconds, and I can make a variable that holds the framerate, if that helps any?
Sorry if I'm confusing.
Thanks for considering !
necromanthus
07-19-2003, 05:51 AM
Ha ha ha,you're a clever guy,but ...
As I said before "Flash Player can't process sounds !
To implement "step back" & "step forward" for a sound file,you need to
access the "PCM level" for that sound (to get access to the sound "bytes").
In other words: you'll need a currentTime instruction (something like currentFrame for movies).
Impossible in Flash at this time !
Anyhow,you can try to "synchronize" two SWF files: one containing the sound file (WAV or MP3) and the other with the "slider".
You must calculate the sound length and set the slider movement speed.
Instead of the slider,you can use a "time display".
The BIG problem is that the calculated speed (FPS) it isn't equal with the "real" speed (the visitor must have a TOP system to reach 100% the theoretical speed).
So ... wait for Flash V7 !
;)
btchwaxfan
07-19-2003, 06:35 AM
Hey, can't fault me for tryin.
Thanks for the advice.
bridelh
07-21-2003, 03:16 AM
Originally posted by necromanthus
In other words: you'll need a currentTime instruction (something like currentFrame for movies).
Impossible in Flash at this time !
I have never played much with sound in Flash/KM, but looking at the actionScript dictionary I see there is :
Sound.duration :Property (read-only); the duration of a sound in milliseconds.
&
Sound.position : Property (read-only); returns the number of milliseconds a sound has been playing.
Sound.start() also seems to have a parameter to start a sound from a specific point in time.
Necro, could these be used for what btchwaxfan requires?
Hilary
--
btchwaxfan
07-21-2003, 11:37 AM
Very interesting, where did you find the ActionScript dictionary at? is this a feature in KM that I missed? Thanks for the hint
w.brants
07-21-2003, 01:53 PM
Here you can fine the macromedia reference on the sound object
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary654.html
but not all functions are supported by KoolMoves I believe.
Bob Hartzell
07-21-2003, 02:47 PM
Press the help button in the action script editor to see what is supported.
necromanthus
07-21-2003, 05:23 PM
Originally posted by bridelh
I have never played much with sound in Flash/KM, but looking at the actionScript dictionary I see there is :
Sound.duration :Property (read-only); the duration of a sound in milliseconds.
&
Sound.position : Property (read-only); returns the number of milliseconds a sound has been playing.
Sound.start() also seems to have a parameter to start a sound from a specific point in time.
Necro, could these be used for what btchwaxfan requires?
Hilary
--
My dear Hilary
I'm working for a while with those instructions.
Unfortunately,we need to SET the Sound position (to solve btchwaxfan's problem).
And,anyhow,we must use KoolMoves ...
cheers
w.brants
07-22-2003, 02:23 AM
I found out the list of supported sound functions shown in the actionscript help file isn't complete. The following functions / properties can be used but aren't listed yet...
Sound.duration
Sound.getBytesLoaded();
Sound.getBytesTotal();
Sound.getTransform();
Sound.onSoundComplete
Sound.position
Sound.setTransform(soundTransformObject);
So you CAN skip forward and backward, check if the sound is is at the end etc.
For example mySound.onSoundComplete lets you check if the sound has ended so you can rewind the counter.
Let's say you have two buttons skipForward and skipBackward and you want them to skip forward or backward 10 seconds in the music. This is an example of how you should be able do it...
skipBack.onPress = function(){
curPos = mySound.position / 1000;
newPos = math.Max ( 0, curPos - 10);
mySound.stop();
mySound.start( newPos );
}
skipForward.onPress = function(){
curPos = mySound.position / 1000;
newPos = math.Min ( mySound.duration / 1000, curPos + 10);
mySound.stop();
mySound.start( newPos );
}
w.brants
07-22-2003, 03:51 AM
I made a little mistake in the skipForward code.
It should be...
skipForward.onPress = function(){
curPos = mySound.position / 1000;
newPos = math.Min ( (mySound.duration -1)/ 1000, curPos + 10);
mySound.stop();
mySound.start( newPos );
}
to start 1/1000sec before the end when the end is reached. Otherwise it won't function properly.
necromanthus
07-22-2003, 05:12 PM
OK guys !
I must repeat myself: you can't SET the currentTime (position) for a sound file !!!
You're talking about Read-Only instructions !
And now ...
This is all you can do in Flash at this time (see the attached file).
No slider & synchronized SWFs because,as I said before,there're a lot
of problems involved.
Also,don't ask for the FUN file because it can't be done using KoolMoves.
BOB is working (hard) to implement a Movie-Library (symbol-library) for KM
and after that,to add some new "tasty" instructions (such as ATTACH).
So,wait a bit for a future version ...
cheers
bridelh
07-22-2003, 08:48 PM
Originally posted by necromanthus
OK guys !
I must repeat myself: you can't SET the currentTime (position) for a sound file !!!
You're talking about Read-Only instructions !
Yes, but as I said before, and Wilbert has shown, you can use the soundOffset parameter of Sound.start() to SET the position.
Same-thing isn't it?
Hilary
--
necromanthus
07-22-2003, 09:49 PM
Originally posted by bridelh
Yes, but as I said before, and Wilbert has shown, you can use the soundOffset parameter of Sound.start() to SET the position.
Same-thing isn't it?
Hilary
--
NO !
Because you must use Sound.stop() first !
Otherwise,you'll get chaotic multi-sounds.
Sound.start(offset,0) and Sound.position are NOT enough for a slider & synchronized SWFs !
Whatever ... I'm tired (I'm going to bed now).
:o
dcahall
07-23-2003, 01:37 PM
This is an interesting discussion. I use another tool to create help and quick start files for our products using a tool called ViewletBuilder (www.qarbon.com) and they have figured out a way to do this. They have a slider bar at the bottom of the SWF file that has a Pause button on it. When you click it, it pauses both the SWF and attached sound file. When you hit Play, it picks up where it stopped.
There must be a way..............
necromanthus
07-23-2003, 05:24 PM
Originally posted by dcahall
They have a slider bar at the bottom of the SWF file that has a Pause button on it. When you click it, it pauses both the SWF and attached sound file. When you hit Play, it picks up where it stopped.
There must be a way..............
This is NOT the solution !
Check my attached file,they do the same thing.
The solution (not available for Flash v6) is to SET the currentTime (position) for the current sound !
sound.position only can read the sound currentTime.
Sound.start(offset,0) only can play another sound starting with "offset" position.
clear enough now ?
;)
btchwaxfan
07-26-2003, 03:20 AM
OK, I've been working on this some more.
I'm pretty close to being able to do this with JavaScript. I've gotten the music to skip ahead and skip back. This example only works in IE (it will work in NN once I finish porting the code (lots of little differences))
http://www.nodzine.net/shvl/
On the left hand side are TEXT controls. Play, Pause, Stop, Rewind, Fastforward. Try them out, look at the source code to see how they work. Very straight forward, the JS is in the OnClick event for the text links. The SWF file can be FForward and Rewound by using the GotoFrame in JS.
Now, I could take all the JS and make it into functions, and have the JS do all the math on currentframe, total frames, number to jump back or forth, etc. I could then _activate_ from the SWF by calling the JS function. However, I would much rather have this all inside the player.
Does this maybe inspire any ideas? (remmeber, only works in IE right now).
Thanks, sorry to be a thorn in your side.
necromanthus, checked out your example of time elapsed display, if that could be done in Kool Moves, that is what I'm looking for.
necromanthus
07-26-2003, 03:48 AM
Originally posted by btchwaxfan
necromanthus, checked out your example of time elapsed display, if that could be done in Kool Moves, that is what I'm looking for.
As I said before,BOB is working to implement a movie-library for KoolMoves.After that ... everything's possible !
Wait a bit for a future version.
cheers
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.