AS3 NetStream doesn't seem to close

2019-08-18 23:37发布

问题:

I'm using the following code to reuse a single FLVPlayback component variable. Would anyone know why the NetStream doesn't stop?

public function clearVideoPlayer(newSource:String):void {

    if (_videoFLV) {
        removeChild(_videoFLV);
        _videoFLV.getVideoPlayer(0).close(); 
        _videoFLV = null;
    }

    _videoFLV = new FLVPlayback();
    _videoFLV.autoPlay = false;
    _videoFLV.autoRewind = false;
    _videoFLV.width = 320;
    _videoFLV.height = 240;

    _videoFLV.source =  newSource;
    addChild(_videoFLV);
}

But after running the function several times, accoring to Scout the NetStream doesn't get closed.

In the Network Events row of the UI I get e.g. 4 x Recieving NetStream audio/video, 5 x Recieving NetStream audio/video, 2 x Recieving NetStream audio/video

This goes on indefinitely, long after the length of any of the videos.

Thanks,

Mark

回答1:

Have you tried to replace

_videoFLV.getVideoPlayer(0).close();

by

_videoFLV.closeVideoPlayer(0);

Moreover, setting _videoFLV to null is useless since you assign a new value to it just after.