I'm experimenting with a site that generates random vimeo urls and plays them full screen with javascript. The site has a vhs appearance and is navigated with the arrow keys. (up arrow to "play" a vid, down to "pause").
I have the player working but am having difficulty detecting 404 and permission errors. I'm using ajax, json, and referenced this helpful thread. This thread as well.
Currently, I get my "Bad ID" alert when a valid url is generated and nothing when a bad url is generated. I would ideally like to re-generate video IDs until successful so users would never see a 404 or be asked for a password. Here is the meat of my code:
// if up arrow is pushed, show play div and hide others
if(e.which == 38) {
//generate video id and url
var video_id = Math.floor((Math.random()*10000000)+1)
var url ="https://vimeo.com/" + video_id;
var video_json = 'http://vimeo.com/api/v2/video/' + video_id + '.json';
//detect 404 with ajax
$.ajax({
type: 'GET',
url: video_json,
data: {format: 'jsonp'},
dataType: 'jsonp',
crossDomain: true,
success: function(resp) {
if (resp["id"]) {
alert ('good ID');
}
else {
alert ('bad ID');
//re-generate video_id until good
}
},
});
console.log(url);
console.log(video_json);
//play video with okvideo
$(function(){
$.okvideo({ source: url,
volume: 100,
loop: true,
hd:true,
adproof: true,
annotations: false,
// disablekeyControl: true,
onFinished: function() { console.log('finished') },
unstarted: function() { console.log('unstarted') },
onReady: function() { console.log('onready') },
onPlay: function() { console.log('onplay') },
onPause: function() { console.log('pause') },
buffering: function() { console.log('buffering') },
cued: function() { console.log('cued') },
});
});
Does anyone have suggestions? I understand this is a kind of hacky way to do accomplish this; there are obviously same-origin barriers at play and I'm open to using the API if this is method is a dead-end. Thanks in advance!