Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
668 views
in Technique[技术] by (71.8m points)

actionscript 3 - In AS3 while using NetStream for video playback how do I seek when I use appendBytes

I am trying to use NetStream to play from a byteArray. Please see this for what I am talking about.

I am able to get this to play the video. However now I need to be able to see to a particular second. I am not able to do this. If I go through the bytearray I know I can get the metadata and the keyframes as required and the offset ( in bytes) as to where each keyframe is at. However there is no way to seek to a particular offset. It only supports seek in seconds and that doesn't seem to work on the byteArray.

How do I go about this ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I got I worked:

// onmetadata function get all timestamp and corresponding fileposition..

function onMetaData(infoObject: Object): void {

    for (var propName: String in infoObject) {

        if (propName == "keyframes") {
            var kfObject: Object = infoObject[propName];
            var timeArr: Array = kfObject["times"];
            var byteArr: Array = kfObject["filepositions"];

            for (var i: int = 0;i < timeArr.length;i++) {
                var tagPos: int = byteArr[i]; //Read the tag size;
                var timestamp: Number = timeArr[i]; //read the timestamp;
                tags.push({
                    timestamp: timestamp,
                    tagPos: tagPos
                });

            }
        }

// onseek click get approximate timestamp and its fileposition
protected

function seek_click(seektime: Number): void {

    var cTime: Number = 0;
    var pTime: Number = 0;

    for (var i: int = 1;i < tags.length;i++) {
        cTime = tags[i].timestamp;
        pTime = tags[i - 1].timestamp;

        if (pTime < seektime) {
            if (seektime < cTime) {
                seekPos = tags[i - 1].tagPos;
                stream.seek(pTime);
                break;
            }
        }
    }
}

/// append bytes on seekposition
private

function netStatusHandler(event: NetStatusEvent): void {

    switch (event.info.code) {

    case "NetStream.Seek.Notify":
        stream.appendBytesAction(NetStreamAppendBytesAction.RESET_SEEK);

        totalByteArray.position = seekPos;

        var bytes: ByteArray = new ByteArray();
        totalByteArray.readBytes(bytes);
        stream.appendBytes(bytes);

        stream.resume();
        break;
    }
}?

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...