NetStream creating a seamless dynamic playlist AS3

674 Views Asked by At

I need to create a playlist dynamically with near seamless transitions in AS3.

I have tried to use the play2 command with .APPEND. It does work in a non dynamic setting. But what I have is this, at the launch of the application, I know what the first video is, then, before that video ends, I will know what the next video to play will be and so on until i get the message that I played the last video.

So, at the beginning, I do not know how many videos there will be, neither do I know the order of the files that will play.

If I try to add a video with APPEND while the stream is already playing, it seems to replace the currently playing video instead of starting to buffer and play only at the end of the current video.

I also can not use appendBytes as the video files have to be in h.264 format

Anyone's help would be greatly appreciated as I do not know in which direction to look anymore. I can give more details if necessary.

Thank you very much.

1

There are 1 best solutions below

0
On

This is a bit of an off-the-cuff answer, but the logic is sound & should give you another direction to pursue.

Firstly, the concept: with Flash video you have 2 completely separate processes occurring simultaneously:

  1. buffering / loading

  2. the video playing

Thus, playing & streaming can & do occur simultaneously, but separately & that is where the logic should be hooked in.

So, on to the implementation: would be to have a primary player, and a secondary (shadow) player / loader. The primary player should be responsible for loading the initial video & playing it.

[& here comes the magic]

Once buffering in the primary player is complete, determined by the NetStream.Buffer.Flush NetStatusEvent on the NetStream object. Then begin buffering the following video in the shadow player, initialising the connection & using NetStream.Pause, to begin buffering, but not playing, while the primary player plays out.

When playing is complete in the primary player (determined by the NetStream.Play.Stop event) you can pass the variables (NetConnention, NetStream & Video) (always passed by reference) from the shadow player over to the primary player & it should continue practically seamlessly. Then clear the values from the shadow player & repeat the above process, waiting for buffering to complete before loading the next video; ad infinitum.

Alternatively, you can have a more balanced approach - although in my mind this will be more resource intensive (as you'll have 2 video players continually active) - and have a primary & secondary player, where they alternate. As soon as one buffer is complete, you begin buffering the next, as soon as playing is complete, you switch from one player to the other.

This will be be pretty fiddly to assemble (hence the lack of an example, as it is complicated, and in essence, your job ;) as you'll be dealing with 2 sets of NetConnections, NetStreams & Videos - which are complicated to begin with, lots of events that require handling...

But, I don't think play2() is your answer here, that is used primarily to reawaken broken/closed NetConnections. The problem that faces you here is seamless asynchronisation of 2 separate NetConnections & NetStreams.

Ping me if you still need assistance/explanation here, this is a bit of an old Q & I don't want to write a few hundred lines of code if you've already moved on...

Best, a.)