Is it possible to use jsfl to export sound files from flash library?

懵懂的女人 提交于 2019-12-01 12:48:18

Took me a bit but I figured out your problem. The issue is with this little property of your sound file: soundItem.originalCompressionType. You can find some detail for the issue here. What is happening in your code is that it will try to export the sound file as the type that it is stored as in the library. i.e. filename.mp3 saves as a .mp3 file and filename.wav saves as a .wav file. If the soundItem.originalCompressionType is equal to "RAW" you cannot save the sound file as a .mp3 file, thus the "filename: false" output. You must save the file as a .wav file. I modified the code a tiny bit when defining the imageFileURL to do this.

// Result of attempts to export will go to the output panel,
// so clear that first fl.outputPanel.clear();

// If bitmaps/audio in the library have been selected, export only
// those. Otherwise, export all bitmaps/audio in the library.

var lib;
if (fl.getDocumentDOM().library.getSelectedItems().length > 0) {
    lib = fl.getDocumentDOM().library.getSelectedItems(); 
} else { lib = fl.getDocumentDOM().library.items; } 

// Get destination directory for files 
var imageFileURLBase = fl.browseForFolderURL("Select a folder."); 
var imageFileURL; 

var totalItems = lib.length;
// Iterate through items and save bitmaps and 
// audio files to the selected directory.
for (var i = 0; i < totalItems; i++) 
{
    var libItem = lib[i];
    if (libItem.itemType == "bitmap" || libItem.itemType == "sound") 
    {
        // Check the audio files original Compression Type if "RAW" export only as a .wav file
        // Any other compression type then export as the libItem's name defines.
        if(libItem.itemType == "sound" && libItem.originalCompressionType == "RAW")
        {
            wavName = libItem.name.split('.')[0]+'.wav';
            imageFileURL = imageFileURLBase + "/" + wavName;
        } else {
            imageFileURL = imageFileURLBase + "/" + libItem.name;
        }
        var success = libItem.exportToFile(imageFileURL);
        fl.trace(imageFileURL + ": " + success);
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!