Copy link to clipboard
Copied
I found a piece of code that can get the length of the current audio, but it is calculated by specifying the audio bit rate. However, the bit rate is not always a fixed value, so it is necessary to automatically obtain the duration information and output it according to different audios.
For example, a piece of audio is 5 seconds long and the frame rate is 25. This piece of audio only occupies 120 frames on the timeline. The 120 here is the information I want to get, or the actual length of the audio.
I checked the manual, but the API for sound does not seem to explain how to get the sound information. Am I missing something?
var dom = fl.getDocumentDOM();
var lib = dom.library;
var soundsBitRate = 705;//specify here the bitrate of your files in Kbits/s
for (i = 0; i < lib.items.length; i++) {
if (lib.items[i].itemType == "sound") {
alert ("Duration of "+ lib.items[i].name + " : " + Math.ceil(FLfile.getSize(lib.items[i].sourceFilePath) / (soundsBitRate/8) / 1000 * dom.frameRate)+ " frames");
}
}
Have something to add?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now