How to use netstream.appendBytes () to dynamically stream HTTP?

I'm trying to figure out how to use dynamic http streaming with flash 10.1, but I can't get the basic functions to work. 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 an error:

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

+3
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1754046/


All Articles