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:
For example, an event handler that handles a file being uploaded to the Media Manager looks like this:
Note: Backend events don't work when previewing your site.
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.
The uploaded file information.
An event that triggers when a file has completed uploading.
The onFileUploaded()
event handler runs when a file has been uploaded to
to the Media Manager using the importFile()
,
upload()
function, or the URL
returned by the getUploadUrl()
function.
The FileEvent
object contains information about the uploaded file and the upload context.
Note: Backend events don't work when previewing your site.
The uploaded file information.
An event that triggers when a video file has completed transcoding.
The onVideoTranscoded()
event handler runs when an uploaded video file
has finished transcoding. Video 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 video and the upload context.
Note: Backend events don't work when previewing your site.
function onVideoTranscoded(event: FileEvent): void;
The uploaded file information.
// Place this code in the events.js file
// of your site's Backend section.
export function wixMediaManager_onVideoTranscoded(event) {
let videoFileInfo = event.fileInfo;
let fileUrl = event.fileInfo.fileUrl;
let height = event.fileInfo.height;
}
/* Full event object:
* {
* "fileInfo": {
* "mediaType": "video",
* "sourceUrl": "https://somedomain.com/img/original-name.mp4",
* "height": 480,
* "mimeType":"video/mp4",
* "hash":"c439e7b7a52f7d7d7263bc0c97dd1ab8",
* "fileUrl":"wix:video://v1/22d494_3d4b9f1c39674519bf636b9bef499659/fileName.mp4#posterUri=22d494_3d4b9f1c39674519bf636b9bef499659f002.jpg&posterWidth=480&posterHeight=480",
* "originalFileName":"fileName.mp4",
* "opStatus": "READY",
* "originalFileName": "original-name.mp4",
* "sizeInBytes":74424,
* "isPrivate":false,
* "width":480,
* "iconUrl":"wix:image://v1/22d494_3d4b9f1c39674519bf636b9bef499659f002.jpg/fileName.mp4#originWidth=480&originHeight=480"
* "parentFolderId":"09057cf95974494c83c8e0b93fd93909"}]"
* },
* "context": {
* "someKey1": "someValue1",
* "someKey2": "someValue2"
* }
* }
*/