2

I'm trying to realize kind of a slideshow in flash, which loops over about 100 h.264 encoded movies. I'm using the NetConnection and NetStream classes for connecting to the files locally on my harddisk (see code below).

private function playMovie():void
{           
        var currentMovie:String = movies[index];
        index = (index + 1) % movies.length;

        netConnection = new NetConnection();
        netConnection.connect(null);

        if(netStream != null)
        {
            netStream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);         
            netStream = null;
        }

        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

        stageVideo.attachNetStream(null);
        stageVideo.attachNetStream(netStream);

        netStream.play(currentMovie);
}

private function netStatusHandler(evt:NetStatusEvent):void
{
        if(evt.info.code == "NetStream.Play.Stop")
        {
            playMovie();
        }
}

public function onMetaData(e:Object):void 
{
        netStream.seek(int(e["duration"]));
}       
public function onXMPData (e:Object):void {}

the problem is that the memory usage of the flashplayer increases with every movie and when reaching about 1.3gb it just ends itself without any errormessage.

my question obviously: how can i fix that?

greg
  • 132
  • 8
  • What do you mean when you say "looping over"? If there is only one video object to display at a time, you should have only one NetConnection and one NetStream, and then switch the URLs to be played when the clips change. – weltraumpirat Feb 18 '11 at 16:38
  • As I said, its a slideshow, so i play one movie at a time and when its finished I start the next one. In the code i posted you can actually see exactly that. So there is exactly one netstream and one netconnection at a time and still memory usage rises. – greg Feb 18 '11 at 16:48
  • No, actually there isn't - you are not freeing up your "old" NetConnection and NetStream objects. See my answer below. – weltraumpirat Feb 18 '11 at 17:14

1 Answers1

1

You must call NetConnection.close() to free the resources, otherwise your memory usage will increase as you see it. It is better practice, though, to keep the same NetConnection and NetStream objects, once created, to play different videos:

private function playMovie():void
{           
    var currentMovie:String = movies[index];
    index = (index + 1) % movies.length;

    if ( netConnection == null ) 
    {
        netConnection = new NetConnection();
        netConnection.connect(null);
    }

    if ( netStream == null )
    {
        netStream = new NetStream(netConnection);
        netStream.client = this;
        netStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        stageVideo.attachNetStream(netStream);
    }

    netStream.play(currentMovie);
}
weltraumpirat
  • 22,544
  • 5
  • 40
  • 54
  • 1
    Sorry to ask, but where exactly do you close the netconnection? – greg Feb 18 '11 at 17:31
  • 1
    I don't, because I'm not creating new ones every time a new movie plays - you did. – weltraumpirat Feb 18 '11 at 17:35
  • 1
    Ok, I guess I finally get it now. Thx – greg Feb 18 '11 at 19:48
  • 1
    Hate to do that now, but after some more testing the increase in memory shows with your approach too. It's getting kind of annoying, since nothing really seams to work. Is there another way to play those movies in flash? – greg Feb 21 '11 at 09:44
  • Do you have a link I can look at? I don't think it's the videos. – weltraumpirat Feb 21 '11 at 10:18
  • I created a minimal Flex-Project, which you can download from here: [link](http://dl.dropbox.com/u/10021046/slideshow/slideshow.zip) – greg Feb 21 '11 at 11:04
  • Okay, I wasn't aware you were using the 10.2 SDK. I'll need to download and install this first. Do you get the same behavior when using the Video class instead of StageVideo? – weltraumpirat Feb 21 '11 at 11:24
  • I verified using the Video class: No increase in memory usage. Every time a new movie starts, some memory is freed up, and some is reallocated. Just as expected. I'll try 10.2 SDK later, when I have more time, but I guess we can narrow the problem down to the StageVideo thingy. Do you have the (VERY recent!) release version of 10.2 player installed? – weltraumpirat Feb 21 '11 at 11:45
  • 1
    First thanks for the effort you put into helping. Thats curious I just tried video-class myself and still have the same "memory leak". I use the the 10.2 standalone flashplayer (downloaded last friday, so I guess it is recent) – greg Feb 21 '11 at 11:46
  • Okay, I read up on StageVideo and I believe the problem might go away if you call NetStream.close() before opening a new movie. Please try and report back if it works - if it doesn't, I'll download 10.2 SDK tonight to look for a working solution. – weltraumpirat Feb 21 '11 at 11:53
  • Hm, strange. I used the browser plugin - it might have something to do with that. – weltraumpirat Feb 21 '11 at 11:54
  • I re-tried using the standalone player. No memory leaks. I'm on a Mac using Snow Leopard 10.6.5, latest player version. – weltraumpirat Feb 21 '11 at 11:59
  • 1
    Ok, I now used the webbrowser plugin on win7, stagevideo enabled and have no memoryloss. So I guess it is something with the standalone player on windows. – greg Feb 21 '11 at 12:06
  • Try using NetStream.close(). It still might work. I also believe this is worth filing a bug report with Adobe ;) http://bugs.adobe.com/flashplayer/ – weltraumpirat Feb 21 '11 at 12:08
  • 1
    I already tried the NetStream.close() method, no luck there. I guess I'll let Adobe know of my little problem. Many thx – greg Feb 21 '11 at 12:11
  • Did you ever find a solution? I'm having a similar problem in an Adobe AIR app on Windows. I don't even need to play several videos, just one that loops forever (with an event that triggers a seek(0) on end) and memory usage increases forever until it hangs. There is obviously a memory leaki, did you find a workaround? – matteo Feb 26 '14 at 17:24