0

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").

VHS

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!

Community
  • 1
  • 1
  • http://stackoverflow.com/questions/10931270/capture-404-status-with-jquery-ajax – adeneo Apr 17 '14 at 18:58
  • @adeneo -Thanks for the prompt response. I've updated my code to include errorThrown arguments; to no avail. I believe this is because they only apply to local url requests (like in the example you linked to). Also in the jquery [documentation](http://api.jquery.com/jQuery.ajax/) it states that the error: handler cannot be called for cross-domain jsonp requests... Any other ideas? – user3397225 Apr 17 '14 at 22:23

0 Answers0