flasharrayshaxenetstream

Seek in embedded FLV with Haxe


In an Haxe project with flash 10 as only target, I would like to seek in an embedded FLV. I tried to do that using the NetStream class and the appendBytes method but I found out that this method can't work because the seek method flushes the buffer when called. Is there any way to achieve this: seeking in an embedded flv?

package;

import flash.utils.ByteArray;
import flash.display.Sprite;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.events.NetStatusEvent;
import flash.events.Event;


// Embedding the video in the SWF here
@:file("Assets/v1.flv") class Vid1 extends  ByteArray {}

class TestProject extends Sprite {

    public var vid:Video;
    public var nc:NetConnection;
    public var ns:NetStream;

    public function new()
    { 
        super();
        addEventListener(Event.ADDED_TO_STAGE, mainSWFLoaded);
    }

    public function playVideo():Void
    {
        vid = new Video();

        nc = new NetConnection();
        nc.addEventListener(NetStatusEvent.NET_STATUS, onConnect);
        nc.connect(null);
    }

    public function onConnect(evt:NetStatusEvent):Void
    {
        if (evt.info.code == 'NetConnection.Connect.Success') {

            ns = new NetStream(nc);

            ns.client = {};
            ns.play(null);

            ns.appendBytes(new Vid1()); 
            vid.attachNetStream(ns);

            // With this line commented, the video plays until the end
            // but if I uncomment it, it will flush the buffer 
            // and the video won't play...
            // ns.seek(3);

            flash.Lib.current.addChild(vid);
        }
    }

    public function mainSWFLoaded(evt:Event):Void 
    {
        playVideo();
    }

    public static function main () 
    {
        flash.Lib.current.addChild(new TestProject());
    }

}

Solution

  • I'm pretty new, so I couldn't get it to work. But it looks like the same thing flash has, where you just have to re-append the bytes after seek flushes the buffer. Here's the article I was looking at, hopefully that helps.

    https://forums.adobe.com/thread/646900?tstart=0