13.4. Getting Playback Time
Problem
You want to determine the time of the current playback position of a sound.
Solution
Use the position
property. To get the
total
time of a sound, use the
duration
property.
Discussion
Flash offers a convenient way to access information about the
playback time for a sound. All Sound
objects
have position
and duration
properties (both are read-only), which reflect the current playback
position and the total duration of a sound. Both values are given in
milliseconds.
trace(mySound_sound.position); trace(mySound_sound.duration);
The position
property updates automatically during
playback. You can get the percentage that corresponds to the current
playback position by dividing position
by
duration
and multiplying the result by 100:
trace(mySound_sound.position/mySound_sound.duration * 100);
Get Actionscript Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.