Calling Mux from Javascript

Here is a quick, simple example of how easy it is to call Mux using Javascript… you simply pass in the URL of a video file you would like transcoded and the output mime-type you’d like to transcode it to.

function doMuxRequest(mediaUrl, mimeType)
{
statusUrl = API_ENDPOINT_SIMPLE_XML;
statusUrl += “TranscodeMediaUrlRequest?”;
statusUrl += “clr=” + API_USER_ID + “:” + API_USER_KEY + “&”;
statusUrl += “url=” + escape(mediaUrl) + “&”;
statusUrl += “sot=” + escape(mimeType) + “&”;

initRequest(statusUrl,’GET’);

window.setTimeout(”doCheckStatus()”, sleepTimeout);
}

The immediate response to this call will a JobID, which you can use to check the status of the transcode, and eventually download the completed output file.

function processReqChange() {

if (req.readyState == 4) {

if (req.responseXML.getElementsByTagName(”jobId”))
{
lastJobId = req.responseXML.getElementsByTagName(”jobId”)[0].firstChild.nodeValue;
}
}
}

This is the most basic use of Mux, but it proves how simple it can be to utilize the cloud. There are many other parameters and functions that can be called, as detailed in the Mux Developer Guide

You can also view the complete Javascript sample source file here: MuxClient.js

Your Thoughts: