I hope someone can help me out with this. I have a situation where I need to add audio files to already developed FLA files. To do this - I have to open the fla file, create a new layer, drag the audio clip to that layer, extend all the layers out to the end of the audio clip, and add a stop.

I was hoping to use JSFL to do this for me. I currently have it where I can select an audio clip in the Library, and run my JSFL script. I takes that sound clip and adds it to a new layer. It creates another layer and adds a stop at the last frame. I can also extend all the layers however many frames I want to. My problem is I cant seem to figure out how to get the length of the sound clip so I know how long to extend all the layers.

Any help would be great.

Thanks

有帮助吗?

解决方案 2

Having a quick look at the JSFL documentation(pdf link) you only have a handful of properties available:

Property Description
soundItem.bitRate                   A string that specifies the bit rate of a sound in the library. Available only for the MP3 compression type. 
soundItem.bits                      A string that specifies the bits value for a sound in the library that has ADPCM compression.
soundItem.compressionType           A string that specifies the compression type for a sound in the library. 
soundItem.convertStereoToMono       A Boolean value available only for MP3 and Raw compression types. 
soundItem.fileLastModifiedDate      Read-only; a string containing a hexadecimal number that represents the number of seconds that have elapsed between January 1, 1970, and the modification date of the original file (on disk) at the time the file was imported to the library. 
soundItem.originalCompressionType   Read-only; a string that specifies whether the specified item was imported as an MP3 file.
soundItem.quality                   A string that specifies the playback quality of a sound in the library. Available only for the MP3 compression type. 
soundItem.sampleRate                A string that specifies the sample rate for the audio clip.
soundItem.sourceFileExists          Read-only; a Boolean value that specifies whether the file that was imported to the Library still exists in the location from where it was imported.
soundItem.sourceFileIsCurrent       Read-only; a Boolean value that specifies whether the file modification date of the Library item is the same as the modification date on disk of the file that was imported.
soundItem.sourceFilePath            Read-only; a string, expressed as a file:/// URI, that represents the path and name of the file that was imported into the Library.
soundItem.useImportedMP3Quality     A Boolean value; if true, all other properties are ignored, and the imported MP3 quality is used

At the moment I can only think of a couple of hacky workarounds...well one in two versions:

  • have the person exporting the sounds also export a .txt with the same name as the sound, which contains the length of the sound. You can load and read this file using FLfile, then using the document's frame rate, calculate the number of frames needed
  • similar to the above method, you can whip out a command line tool whose sole purpose is to output the length of an audio file(using the sound's sourceFilePath property) or using an existing tool(*). You can call a command line application using the undocumented FLfile.runCommandLine().

A few examples of command line tools are ffmpeg(e.g. ffmpeg -i yourAudioFile) or MediaInfo. I'm sure there are others out there. It depends what operating system you need to use and if the tool can be easily installed. Ideally you would use something that outputs just the duration, but if you get more data, you should be able to parse the output and get the duration. Also note that that the function will return 1 for successful execution or 0 otherwise, so you will need to have a command that will also write the output to a text file you can read with jsfl.

其他提示

If your audio files are encoded with a constant bitrate, you can eventually get the length of your files and calculate their duration, using the FLfile.getSize() method.

Here is a jsfl snippet that calculates and shows the frame durations of each sound from your library:

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");
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top