I have built a simple media player panel for Adobe Premiere Pro that allows users to preview audio files from within the application, rather than trawling through windows explorer and opening in VLC.
I’m using the simple HTML player to play the files back, but what I’d like to do is have the option to import the selected track directly into Premiere.
Everything works as it should, apart from the Import function. When the button is clicked nothing happens, not even the error messages.
Any thoughts?
My current code looks like this:
`const ingestButton = document.createElement('button');
ingestButton.textContent = 'Import';
ingestButton.addEventListener('click', async () => {
try {
const file = await entry.getFile();
const filePath = file.path || file.name;
if (typeof CSInterface !== 'undefined') {
const csInterface = new CSInterface();
csInterface.evalScript(`importFileToPremiere`, (response) => {
if (response === "success") {
console.log("File imported successfully into Premiere.");
} else {
console.error("Failed to import file into Premiere:", response);
}
});
} else {
console.warn("CSInterface is not available. Are you running this in a CEP panel?");
}
} catch (error) {
console.error("Error processing file for Premiere:", error);
}`
with an accompanying .jsx added to the main Premiere.jsx file:
`function importFileToPremiere(filePath) {
try {
// Create a File object for the file to be imported
var fileObj = new File(filePath);
if (!fileObj.exists) {
return "The specified file does not exist: " + filePath;
}
// Get the active Premiere project
var project = app.project;
if (!project) {
return "No active project found in Adobe Premiere.";
}
// Use ImportOptions to import the file
var importOptions = new ImportOptions(fileObj);
if (importOptions.canImportAs(ImportAsType.CLIP)) {
importOptions.importAs = ImportAsType.CLIP;
}
project.importMedia([fileObj.fsName], true, project.getInsertionBin(), false);
return "success";
} catch (e) {
return "Error importing file into Premiere: " + e.message;
}`
