Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Trouble Importing File into Premiere Timeline via javascript

$
0
0

I'm trying to make an extension for Premiere Pro that allows me to import sound effects at the current playheads position with an assigned keybind for that sound effect. I'm having trouble importing the sound effect at the playhead. The sound effect is being imported into the project but is not being placed in the timeline. Here is the current code I have.The log is showing the playheads position is accurately being found but then the file just gets imported, not placed into the timeline at the playheads position. Here is my current code:

var soundFilePath = "C:\\Users\\adgea\\OneDrive\\Documents\\DING 1.mp3"; // Replace with the actual pathimportSoundEffectAtPlayhead(soundFilePath);function importSoundEffectAtPlayhead(filePath) {    app.enableQE();    var project = app.project;    if (app.project && app.project.sequences && app.project.sequences.length > 0) {        var activeSequence = app.project.activeSequence;        if (activeSequence) {            $.writeln("Active sequence name: " + activeSequence.name);            var fileToImport = new File(filePath);            if (fileToImport.exists) {                try {                    var importedFiles = app.project.importFiles([filePath], 1, app.project.rootItem, 0);                    if (importedFiles && importedFiles.length > 0) {                        var newFootageItem = importedFiles[0];                        var audioTrack = getAudioTrack(activeSequence);                        if (audioTrack) {                            var playheadPosition = activeSequence.getPlayerPosition();                            var timeInSeconds = activeSequence.timeToFrames(playheadPosition) / activeSequence.getFrameRate();                            audioTrack.insertClip(newFootageItem, timeInSeconds);                        } else {                            alert('No targeted audio track found in the sequence.');                        }                    } else {                        $.writeln('File was found but could not be imported: '+ filePath);                    }                } catch (e) {                    $.writeln('Error importing file: '+ e.toString());                }                $.sleep(1000);            } else {                alert('File does not exist at the specified path.');            }        } else {            alert('No active sequence found in the project.');        }    } else {        alert('No sequences found in the project. Please create a sequence.');    }}function getAudioTrack(sequence) {    for (var i = 0; i < sequence.audioTracks.numTracks; i++) {        var track = sequence.audioTracks[i];        if (track.targeted) {            return track;        }    }    return null;}

I thought an easy way to solve this would be to initiate the native "insert" function in premiere by pressing the native keybind (,) but extend script can't do that so I'm lost.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>