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 ...
I have found the solution to my problems. You must start with ns.play(null) instead of ns.play('url to download');
精彩评论