You can just loop through the array:
var url;
for (var i = 0; i < v.renditions.length; i++) {
if (v.renditions[i].frameWidth == 1248) {
url = v.renditions[i].url;
break;
}
}
Frage
I am trying to loop through the renditions array of my videos in brightcove and keep coming up unsuccessful no matter what I try.
document.getElementById('divMeta.render').innerHTML = v.renditions;
The result of this code is:
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
showing that there are 6 separate renditions.
videos: Array[20]
0: Object
FLVFullLength: Object
FLVURL: "http://brightcove.vo.llnwd.net/pd16/media/1978114949001/1978114949001_2223781677001_Lindy-Fish---Game-Cleaning-Station-Features---Benefits.mp4?pub
Id=1978114949001&videoId=2223734749001"
creationDate: "1363191473140"
customFields: Object
economics: "AD_SUPPORTED"
id: 2223734749001
lastModifiedDate: "1363200126320"
length: 45094
linkText: null
linkURL: null
longDescription: null
name: "Lindy Fish & Game Cleaning Station Features & Benefits"
playsTotal: 19
playsTrailingWeek: 19
publishedDate: "1363191473140"
referenceId: null
renditions: Array[6]
0: Object
1: Object
audioOnly: false
controllerType: "DEFAULT"
displayName: "Lindy Fish & Game Cleaning Station Features & Benefits.mov"
encodingRate: 1616956
frameHeight: 700
frameWidth: 1248
id: 2223780276001
referenceId: null
remoteStreamName: null
remoteUrl: null
size: 9153763
uploadTimestampMillis: 1363191560801
url: "http://brightcove.vo.llnwd.net/pd16/media/1978114949001/1978114949001_2223780276001_Lindy-Fish---Game-Cleaning-Station-Features---Benefits.mp4?pub
Id=1978114949001&videoId=2223734749001"
videoCodec: "H264"
videoContainer: "MP4"
videoDuration: 45094
__proto__: Object
2: Object
3: Object
4: Object
5: Object
length: 6
As you can seen in the text copied from my console log above, inside the renditions there are 6 different ones I would like to call the url of the one that the frameWidth = 1248.
Any suggestions?
Lösung
You can just loop through the array:
var url;
for (var i = 0; i < v.renditions.length; i++) {
if (v.renditions[i].frameWidth == 1248) {
url = v.renditions[i].url;
break;
}
}