5
votes

What does error code 0 mean in YouTube Flash API? It occurs when trying to play some videos with the API. Other error codes are explained in the API Reference, but not error code 0.

How do I make the YouTube player play all videos, just like it does on YouTube Player Demo?

FLA and SWF files: https://s3.amazonaws.com/YouTubeAPIError0/YouTubeAPIError0.zip

package {
    import flash.system.Security;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import fl.data.DataProvider;
    import fl.controls.ComboBox;
    import fl.controls.TextArea;

    public class YouTubeAS3 extends MovieClip {
        public var VidHolder:MovieClip;
        public var VidSelection:ComboBox;
        public var traceArea:TextArea;

        private var player:Object;
        private var loader:Loader;
        private var vidCollection:DataProvider;

        public function YouTubeAS3():void {
            Security.allowInsecureDomain("*");
            Security.allowDomain("*");

            vidCollection = new DataProvider();
            vidCollection.addItem({data:"eDdI7GhZSQA", label:"Video 1"});
            vidCollection.addItem({data:"S09F5MejfBE", label:"Video 2"});
            vidCollection.addItem({data:"QUwxKWT6m7U", label:"Video 3"});
            vidCollection.addItem({data:"TAbnQZZ6QXc", label:"Video 4"});
            vidCollection.addItem({data:"QH2-TGUlwu4", label:"Errorless Video"});

            VidSelection.dataProvider = vidCollection;
            VidSelection.addEventListener(Event.CHANGE, cueVideo);

            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
            loader.load(new URLRequest("http://www.youtube.com/apiplayer?version=3"));
        }

        private function onLoaderInit(event:Event):void {
            VidHolder.addChild(loader);
            loader.content.addEventListener("onReady", onPlayerReady);
            loader.content.addEventListener("onError", onPlayerError);
            loader.content.addEventListener("onStateChange", onPlayerStateChange);
            loader.content.addEventListener("onPlaybackQualityChange", onVideoPlaybackQualityChange);
        }

        private function onPlayerReady(event:Event):void {
            traceArea.text += "player ready: " + Object(event).data + "\r";
            player = loader.content;
            player.setSize(480, 360);
            VidSelection.selectedIndex = 0;
            VidSelection.dispatchEvent(new Event(Event.CHANGE));
        }
        private function cueVideo(event:Event):void {
            traceArea.text += "switch to: " + event.target.selectedItem.label + "\r";
            player.cueVideoById(event.target.selectedItem.data);
        }

        private function onPlayerError(event:Event):void {
            traceArea.text += "player error: " + Object(event).data + "\r";
        }

        private function onPlayerStateChange(event:Event):void {
            traceArea.text += "player state: " + Object(event).data + "\r";
        }

        private function onVideoPlaybackQualityChange(event:Event):void {
            traceArea.text += "video quality: " + Object(event).data + "\r";
        }
    }
}
3
My guess would be that it was a bug in the Youtube player, where the Error wasn't properly initialized before dispatching the event. Unfortunately, I can't duplicate what you're seeing - the sample code you provided works just fine for me when I run it, with no errors at all.Josh Buhler
@joshbuhler What makes your machine special? I was even connecting through U.S./Canada proxies multiple times and the error 0 persisted for the first 4 videos.Pleo
Is anyone else getting this bizarre error with the code above?Pleo
Nothing special that I know of. Just downloaded the code and ran it. You mention the proxies - are you running this outside the US? If so, have you tried it with videos that wouldn't be affected by what country you're in?Josh Buhler
@joshbuhler So you say each of the first 4 videos play as they should for you with the sample code? Well, the fact is that I need all videos that play fine on YouTube site to be played trouble-free with the API. All of the first 4 videos play normally when I view them on the YouTube site (I'm outside U.S.), but not when I try to play them with the API. If I knew that at least visitors from U.S. would be able to view all videos, it'd give some relief.Pleo

3 Answers

0
votes

I've had an error state of 0 - when the video times out.

If you look in the developer tools for whichever browser you're working with you should see a callout called 'videoplayback' which will have timed out. I have it timing out after 7.5 minutes, but that might be connection related.

Also, a 'timeout' error isn't covered in the currently documented error states.

0
votes

This is the same question as YouTube AS3 Player API Error Code 0 ... of course, that question doesn't have an answer, either (interesting, though, that the same 4 videos are used as examples of unplayable vids).

The only suggestion I'd have would be to look for a pattern in the data. For example, the v3 data API shows that all 4 videos you list which aren't playing are blocked in Germany, while the one you offer that does play has no such block. This would lead to the assumption that perhaps the error is related to a region block (note that a region block is different from the "embeddable" block, which is metadata that the uploader can set). The videos blocked in Germany are all done so because Vevo isn't allowed there, and they're all Vevo videos.

I'm not, of course, necessarily suggesting that the "unplayableness" is intentional, although it could be; I'm not aware of direct documentation that details what happens when the API (as opposed to the Youtube site, which uses different methods for playing the videos so you can't make any direct comparisons) tries to play a region blocked video. Perhaps @Dominic Orme is correct in that it's related to a timeout, a timeout caused by the region block (or by attempting to use a proxy to bypass the region block).

You can test this theory by finding other videos that would fit the pattern. For example, are all Vevo videos unplayable with your code? Are videos blocked in other countries also unplayable?