Introduction

Wix Media events are triggered when certain events occur with files created using the Media API. You can write event handlers that react to these events. Event handler functions receive data that corresponds to the event that has occurred. Use event handlers to create custom responses to media events.

To add a media event handler, add an events.js file to the Backend section of your site if one doesn't already exist. All event handler functions for your site are defined in this file.

Event handler functions are defined using the following pattern:

Copy

For example, an event handler that handles a file being uploaded to the Media Manager looks like this:

Copy

Note: Backend events don't work when previewing your site.

Did this help?

onAudioTranscoded( )


An event that triggers when an audio file has completed transcoding.

The onAudioTranscoded() event handler runs when an uploaded audio file has finished transcoding. Audio files that have been imported aren't immediately available until the transcoding has completed.

It is fired after the onFileUploaded event, and after the transcoding has completed. The FileEvent object contains information about the uploaded audio file and the upload context.

Note: Backend events don't work when previewing your site.

Method Declaration
Copy
function onAudioTranscoded(event: FileEvent): void;
Method Parameters
eventFileEventRequired

The uploaded file information.

An event when an audio file has been transcoded
JavaScript
// Place this code in the events.js file // of your site's Backend section. export function wixMediaManager_onAudioTranscoded(event) { let audioFileInfo = event.fileInfo; let fileUrl = event.fileInfo.fileUrl; let size = event.fileInfo.sizeInBytes; } /* Full event object: * { * "fileInfo": { * "mediaType": "audio", * "mimeType": "audio/mpeg", * "sourceUrl": "https://somedomain.com/img/original-name.mp3", * "fileUrl": "wix:audio://v1/2123bc_6aec991ee66c4c16a783433cc7dca232.mp3/fileUrl.mp3#" * "hash": "5a9a91184e611dae3fed162b8787ce5f", * "opStatus": "READY", * "originalFileName": "original-name.mp3", * "sizeInBytes": 8414449, * "isPrivate": false * }, * "context": { * "someKey1": "someValue1", * "someKey2": "someValue2" * } * } */
Did this help?