davide0033
davide0033

Reputation: 1

recreating the old youtube mobile player whit flash

i have an old "smartphone", since youtube killed the old flash player (html5 video doesn't work and it has so few ram that i can't even load the full "the old net" i never worked whit flash before (and i never really did anything similar)

the basic idea is to make an host a simple html page that ask you the id of the video, it download it, downscale it to 144p, convert in flash and send it to the phone the problem is, i don't know how to use the buffering, so it work whit short videos, but when they're too long it fail to buffer everything when loading the page and break i would like something like how youtube work (load piece by piece) any ideas on how should i do this?

btw, the old phone is a samsung GT-S5260 whit samsung dolfin 2.0

Upvotes: -1

Views: 88

Answers (1)

Organis
Organis

Reputation: 7316

Ok, my AS3 is kinda rusty already, but I think it should work as the following.

First, you pass the video URL to the Flash application via FlashVars, it is a special HTML tag.

If you form HTML tags outright (figure urls and dimensions on your own):

<object width="640" height="480" type="application/x-shockwave-flash" id="X" name="X" data="flvplayer.swf" >
    <param name="movie" value="flvplayer.swf">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="true" />
    <param name="quality" value="high" />
    <param name="wmode" value="opaque">
    <param name="FlashVars" value="flvurl=movieurl.flv" />
    <embed width="640" height="480" type="application/x-shockwave-flash" id="X" name="X" src="flvplayer.swf"
        allowScriptAccess="sameDomain"
        allowFullScreen="true"
        quality="high"
        flashVars="flvurl=movieurl.flv"
        pluginspage="http://www.adobe.com/go/getflashplayer"
    ></embed>
</object>

Alternately, if you activate the Flash application through the SWFObject:

<script type="text/javascript">
    var flashvars = {
        "flvurl=movieurl.flv"
    };
    var params = {
        allowScriptAccess: "sameDomain", 
        allowFullScreen: "true",
        wmode: "opaque",
        quality: "high",
        menu: "false"
    };
    var attributes = {};

    swfobject.embedSWF("flvplayer.swf", "X", "640", "480", "9.0.0","expressInstall.swf", flashvars, params, attributes);
</script>

Ok. Next step, you need the means to build that flvplayback.swf. In order to do so, you need either AIR SDK or Flex SDK (optionally FlashDevelop tool because it made things so much easier back then, auto-downloaded SDKs too, but I have no idea if it works these days) or Flash/Animate IDE. I believe it is still possible to find some kind of tutorial like "build my first Flash project".

Then, the very application in question is rather simple one. The one below goes in a form of a single class, which should be the main class if you build thru AIR/Flex SDK or assigned as the document class if it is Flash/Animate.

package
{
    import flash.net.NetConnection;
    import flash.net.NetStream;
    
    import flash.media.Video;
    import flash.events.Event;
    import flash.display.Sprite;
    
    public class Main extends Sprite
    {
        private var playback:Video;
        
        public function Main()
        {
            // Being able to access the stage is important.
            if (stage) onStage(null);
            else addEventListener(Event.ADDED_TO_STAGE, onStage);
        }
        
        private function onStage(e:Event):void
        {
            // The fact we are here means the stage is present and available.
            removeEventListener(Event.ADDED_TO_STAGE, onStage);
            
            // Obtain the video URL.
            // That's why being able to access the stage was important.
            var flvurl:String = stage.loaderInfo.parameters["flvurl"];
            
            // If there's no URL provided, just stop.
            // Normally I'd put some visual alert here.
            if (!flvurl) return;
            
            // Set up stage a bit.
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            stage.stageFocusRect = false;
            stage.showDefaultContextMenu = false;
            
            // Build and start the video player.
            var NC:NetConnection;
            var NS:NetStream;
            
            NC = new NetConnection;
            NC.connect(null);
            NS = new NetStream(NC);
            NS.play(flvurl);
            
            flvplayback = new Video;
            flvplayback.attachNetStream(NS);
            
            // Make it the size of the stage right away
            // then subscribe to any size changes.
            onResize(null);
            stage.addEventListener(Event.RESIZE, onResize);
            
            // Finally, attach the video player to the display list.
            addChild(flvplayback);
        }
        
        private function onResize(e:Event):void
        {
            flvplayback.width = stage.stageWidth;
            flvplayback.height = stage.stageHeight;
        }
    }
}

I cannot promise this would work right away, although I think it probably will. The idea is correct, the logic is straight, I just might forgot something or made some typos.

Upvotes: 1

Related Questions