|
|
|
|
|
Brightcove :
Developers :
Media APIs :
Re: Selecting Rendition using the Media API
|
|
|
|
|
|
|

|
Selecting Rendition using the Media API
|
|
EJ
Contributor
Posts: 10
Registered: 02-11-2009

Message 1 of 10

Viewed 2,769 times
|

|
|
I noticed that using the Player API, you are able to select the rendition using: setRenditionSelectionCallback(callback:Function):void Does anyone know of a way to select a rendition using the Media API. Currently the API only returns the 512 kbps rendition. Can this be done using an API call? http://api.brightcove.com/services/library?command=find_video_by_id &video_id=149210661776&fields=name,renditions &token=0Z2dtxTdJAxtbZ-d0U7Bhio2V1Rhr5Iafl5FFtDPY8E. Is there something missing that I can add to the call to select a rendition by bitrate? Thanks for the help
|
Solved!
 Go to Solution
|
|
|
05-19-2009 01:14 PM
|
|
|
|
|

|
Re: Selecting Rendition using the Media API
|
|
BC-Sean
Brightcove Team
Posts: 76
Registered: 01-09-2009

Message 2 of 10

Viewed 2,760 times
|

|
First you need to get a url enabled token from customer support. Once you have that you should be able to recieve an array of renditions each should look something like this:
"renditions": [ { "displayName": "Punisher.mov", "encodingRate": 1500000, "frameHeight": 768, "frameWidth": 1024, "referenceId": null, "remoteStreamName": null, "remoteUrl": null, "size": 8144122, "type": "FLV_FULL", "url": "http://brightcove.vo.llnwd.net/d5/unsecured/media/270881182/270881182_4664369001_Punisher.flv", "videoCodec": "ON2", "videoDuration": 66131 }...
Then you just compare the encoding rate to the one you want. We return all renditions that exist, let me know if you see more than one in the media module but only one in the api.
Thanks, Sean
|
|
|
|
05-19-2009 01:45 PM
|
|
|
|
|

|
Re: Selecting Rendition using the Media API
|
|
EJ
Contributor
Posts: 10
Registered: 02-11-2009

Message 3 of 10

Viewed 2,752 times
|

|
|
Thanks Sean, I'm not the strongest Javascript guy, so I was wondering if there were any examples on the Brightcove developer site on how to do this, or if you could possible help me out with an example? Currently, I am using the API example. I have included my code below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Player API Example - HTML</title> <link rel="stylesheet" href="displayTitles.css"/>
<script> function JSONscriptRequest(fullUrl) { // REST request path this.fullUrl = fullUrl; // Keep IE from caching requests this.noCacheIE = '&noCacheIE=' + (new Date()).getTime(); // Get the DOM location to put the script tag this.headLoc = document.getElementsByTagName("head").item(0); // Generate a unique script tag id this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++; }
// Static script ID counter JSONscriptRequest.scriptCounter = 1;
// buildScriptTag method // JSONscriptRequest.prototype.buildScriptTag = function () {
// Create the script tag this.scriptObj = document.createElement("script"); // Add script object attributes this.scriptObj.setAttribute("type", "text/javascript"); this.scriptObj.setAttribute("charset", "utf-8"); this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE); this.scriptObj.setAttribute("id", this.scriptId); } // removeScriptTag method // JSONscriptRequest.prototype.removeScriptTag = function () { // Destroy the script tag this.headLoc.removeChild(this.scriptObj); }
// addScriptTag method // JSONscriptRequest.prototype.addScriptTag = function () { // Create the script tag this.headLoc.appendChild(this.scriptObj); } </script> <script> // The web service call var token = "xxxxxxxxxxxx."; var req = "http://api.brightcove.com/services/library?"; req += "command=find_all_videos&token=" + encodeURIComponent(token); // tokens need to be URL-encoded req += "&fields=id,name,shortDescription,FLVURL,thumbnailURL,length,renditions&callback=response";
function initCall() { // Create a new request object bObj = new JSONscriptRequest(req); // Build the dynamic script tag bObj.buildScriptTag(); // Add the script tag to the page bObj.addScriptTag(); } // Define the callback function // writes out the HTML for each title item in the list function response(jsonData) {
var items = jsonData["items"]; var tDiv = document.getElementById("titleList"); var i=0; while (i<items.length) { var str = ""; str += '<div class="VideoEntryHolder">';
str += '<div class="VideoPicHolder">'; str += '<a href="'+ items[i].FLVURL+'"/>'; str += '<img src="' + items[i].thumbnailURL +'" width="120"/></a></div>'; str += '<div class="VideoInfoHolder">' + items[i].name + ' (' + formatTime(items[i].length) + ')'+ '<br>'; str += '<font class="style3">' + items[i].shortDescription + '</font>'; str += '</div>'; str += '</div>'; str += '</div>'; str += '<br>';
tDiv.innerHTML += str; i++; } } // time is stored in milliseconds; we need to convert to a mm:ss display format function formatTime(time) { var t_secs = Math.round(time/1000); var mins = Math.floor(t_secs/60); var secs = t_secs - (mins*60); return mins + ":" + secs; }
</script> </head>
<body onload="initCall()">
<div id="titleList"> </div>
</body> </html>
|
|
|
|
05-19-2009 03:36 PM
|
|
|
|
|
|
|

|
Re: Selecting Rendition using the Media API
|
|
EJ
Contributor
Posts: 10
Registered: 02-11-2009

Message 5 of 10

Viewed 2,737 times
|

|
|
Hi Sean, I gave that a try, I replaced the 512000 with the bitrate that I was looking for, and still no luck. It seems to detect the bitrate I'm looking for, but when it creates the link, it is undefined, so it seems that rend.url is not working.
|
|
|
|
05-20-2009 02:54 PM
|
|
|
|
|
|
|

|
Re: Selecting Rendition using the Media API
[ Edited ]
|
|
jerjou
Contributor
Posts: 38
Registered: 12-11-2008

Message 7 of 10

Viewed 2,707 times
|

|
Javascript is weird in that the for-loop syntax iterates on the index rather than the value. So, what once was:
for( var rend in items[i].renditions){ if(rend.encodingRate == 512000){ str += '<a href="'+ rend.url+'">'; break; } }
should actually be:
for( var rend in items[i].renditions){ if(items[i].renditions[rend].encodingRate == 512000){ str += '<a href="'+ items[i].renditions[rend].url+'">'; break; } }
A little cleaner:
var renditions = items[i].renditions; for(var j=0; j<renditions.length; j++) { if(renditions[j].encodingRate == 512000){ str += '<a href="'+ renditions[j].url+'">'; break; } }
Message Edited by jerjou on 05-26-2009 10:40 AM Message Edited by jerjou on 05-26-2009 10:41 AM
|
 Accepted Solution
|
|
|
05-26-2009 10:36 AM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|