3

I am trying to figure out how to use http dynamic streaming with flash 10.1 but I can't get the basic functions working. What is the syntax for using appendbytes with a video file?

package com.player {

import flash.display.Stage;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.events.Event;
import flash.utils.ByteArray;

public class Player extends Sprite {

    const vurl = "file://E:/clip.flv"

    private var nc:NetConnection;
    private var ns:NetStream;
    private var vo:Video;



    private var urlstream:URLStream;

    public function Player() {

        nc = new NetConnection();
        nc.connect(null);

        ns = new NetStream(nc);
        ns.client = new StreamClient();

        vo = new Video();
        vo.attachNetStream(ns);

        addChild(vo);

        ns.play(vurl);

        var urlrequest:URLRequest = new URLRequest(vurl)
         urlstream = new URLStream();

        urlstream.addEventListener(Event.COMPLETE, completeHandler);

        urlstream.load(urlrequest);



    }

    private function completeHandler(event:Event):void {
        trace("completeHandler: " + event);

        var bytes:ByteArray = new ByteArray();

        urlstream.readBytes(bytes);

        ns.appendBytes(bytes);
    }


}

}

Running this gives me the error:

TypeError: Error #2004: One of the parameters is invalid. at flash.net::NetStream/appendBytes() at ...

user319862
  • 1,797
  • 2
  • 24
  • 32

1 Answers1

2

I have found the solution to my problems. You must start with ns.play(null) instead of ns.play('url to download');

user319862
  • 1,797
  • 2
  • 24
  • 32
  • Have you been able to figure out how to do true HTTP streaming (i.e. stitching together multiple streams). I have tried to stitch together two different FLV files, but always get a skip in them. – Scott Dec 28 '10 at 20:09
  • not really an answer to connect to null... check out http://stackoverflow.com/a/7948112/280551 and the eventual flashdoc for more explanation. the vague error suggests that your NetStream Object was not in "Data Generation Mode", e.g. you opened/wrote to it. perhaps the URL could be overridden later? but that's pretty lame, on a streaming front, anyway... – edwardsharp Nov 29 '11 at 01:49