Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How does JSFL get the duration of audio?

Contributor ,
Apr 08, 2025 Apr 08, 2025

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");
    }
}
TOPICS
Code
85
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation