2

I've been searching for this for a while, and either my google-fu is weak or there is no easy to find answer yet...

I am using a NetStream to stream a video file from anywhere. The NetStream is NOT connected to any server. Here is the code:

            // Create new connection and stream
            _netCon = new NetConnection();
            _netCon.connect(null);

            _netStream = new NetStream(_netCon);
            _netStream.client = this;
            _netStream.play(url);

            // Configure video layer
            _videoLayer.attachNetStream(null);
            _videoLayer.attachNetStream(_netStream);
            _videoLayer.width = stage.stageWidth;
            _videoLayer.height = stage.stageHeight;

This basically works, of course, but the video always starts playing only when it is fully loaded. It also passes the metadata only then. But the main reason to use a NetStream is so that you can play a video BEFORE it is fully loaded.

I tried playing around with the bufferTime property, but to no avail. Also made sure that there is no caching involved when loading the video. I always load a "new one" by adding some "?bla=date" value behind the url.

Is it possible that the "real" streaming only works when really connected to a server? Or am I missing something else?

TheSHEEEP
  • 2,961
  • 2
  • 31
  • 57
  • When you say not connected to a server, do you mean you are testing in a local environment? Also, what encoding settings did you use on the video file? – James Tomasino Feb 09 '12 at 12:58
  • When I say not connected to a server, I mean "_netCon.connect(null); " instead of "_netCon.connect(server-url);". The codec settings, I cannot guarantee, as those files are not in my hand. Do not all codecs support streaming as I want it? – TheSHEEEP Feb 09 '12 at 13:12

3 Answers3

2

It is probably waiting for metadata - that's surely was the case with .h264 video. I've never heard it was fixed, so, probably it's not. If that's your files you are trying to play, use something like ffmpeg to move the metadata to the beginning of the file, but if it's not - you could try to stream it yourself using URLStream and then feed it to NetStream via appendBytes() (the later I didn't try, but in theory should be possible).

  • Yep, we use h264 videos (I just had a look). I'll ask how badly we need the immediate playback and probably try the URLStream approach. – TheSHEEEP Feb 09 '12 at 14:09
  • Yeah, I agree: Encoding and container settings can definitely cause issues like this. H.264 as a *specification* has an ability to be stream hinted, but not all encoders that implement that codec do it by default. Tools like ffmpeg or mp4box can rewrap the video in a hinted container (.mp4) that should work for streaming. – merv Feb 09 '12 at 20:01
1

Flash is very liberal with the supported settings in FLVs, but I'm not sure about it being 100%. As for the netConnection, that's pretty standard unless you're supporting a streaming video. You are just looking for a playing solution that buffers, then plays a video immediately, rather than waiting for the entire FLV to load. That's also pretty much the most basic operation of the netstream object. Without looking over your complete code, I can tell you that NetStream is extremely buggy and particular. It may be that you are doing everything right, but in slightly the wrong order. Or maybe you are listening to events that don't exist, because NetStream uses callbacks instead.

Here's two blog posts I wrote that go into NetStream and Video issues in greater depth, and what I did to solve them last time. They might shed some light on where your setup is going astray.

NetStream Sucks

Streaming Video Player

James Tomasino
  • 3,520
  • 1
  • 20
  • 38
  • Well, the code I showed really is all that has to do with the video playing. There is nothing else that affects the video playback. I just forgot to add the addChild() for the _videoLayer, which is actually an instance of the Video class. As far as I can see, your streaming video player does the exact same (plus a ton of additional functionality): Call .play(url) on the NetStream and wait for the video to begin. – TheSHEEEP Feb 09 '12 at 14:09
  • Pretty much, yes. The event handling and internal status codes are wrapped up a bit, though. – James Tomasino Feb 09 '12 at 15:39
0

To clear things up:

The problem was indeed within the position of the metadata within our video files. We did not resolve that for the time being as we had more important issues. But we will come back to that, moving the metadata position to the beginning of the video files.

Thanks for the help!

TheSHEEEP
  • 2,961
  • 2
  • 31
  • 57