Weblog / Blog article: Tiny Flash Video Player

Tiny Flash Video Player

This is from my talk, How to Shoot, Edit, and Publish Web Video, at MAX 2007. For more step-by-step tutorials purchase my book, Producing Flash CS3 Video.

To create a very small swf that plays Flash Video without hiccuping on cue points, follow these steps.

  1. First download the example file, simple-player.zip.
  2. Open the Library Panel. (Window > Library). From the fly-out menu, choose New Video...

    351
  3. In the Video Object properties dialog, name the video object video.

  4. The video object will now appear in the Library panel. Select the video layer in the Timeline window and drag the video object in the Library to the stage.
  5. Select the instance on the stage and use the Properties panel (Window > Properties) to set the instance's name, position and size. Call it myVideo. Set its x and y position to 0,0. Set its width and height to 320 × 240.

    Properties panel
  6. Select frame 1 in the Actions layer and enter the following code in the Actions panel. Read the comments to understand what each line of code does. I've put in a fun analogy to help those new to video ActionScript code.
     
    // create a connection to bring in content into Flash
    // this is like laying down video cable
    var nc:NetConnection = new NetConnection();
     
    // no need to connect when not connecting to a Flash Media Server
    nc.connect(null);
     
    // create a stream and connect it to the netconnection object
    // this is akin to sending a video signal on the cable
    var ns:NetStream = new NetStream(nc);
     
    // attach the stream to a video on the stage
    // this is like connecting the cable to a tv
    myVideo.attachNetStream(ns);
     
    // set the source and play the video
    // turn on the tv
    ns.play("bubbles.flv");
     
    // ignore metadata and prevent Flash player exceptions
    var videoClient:Object = new Object();
    ns.client = videoClient;
    videoClient.onMetaData = onMetaData;
    function onMetaData(info:Object):void {
        // do nothing, or something
    }
     

NOTE: If you have the latest beta of the Flash Player (codenamed Moviestar and also known as Flash Player 9 update 3) and you want to play H.264 encoded video, change ns.play("bubbles.flv") to ns.play("text-tornado.m4v"). Note that you'll need to download the beta player from Adobe Labs and preview the generated SWF in a web browser. Previewing won't work in Flash Professional CS3 at this point in time (October 2007).

One Response to “Tiny Flash Video Player”

  1. Streaming media - Producing Flash CS3 Video … at PePo’s weblog Says:

    [...] en zodoende inzicht te krijgen in de benodigdheden en theorie. Bijvoorbeeld in zijn blok-artikel Tiny Flash Video Player noemt hij in de code MetaData (al wordt het niet gebruikt in dit voorbeeld!) en wat gewijzigd moet [...]