Jump to content
Search Community

Suggestion: Wrapper for NetStream events

bildschirmsport test
Moderator Tag

Recommended Posts

Hi again,

 

while working with LoaderMax and the VideoLoader I realized I would be nice to have an event wrapper class for NetStream Events. In my opinion NetStream events are really painful to work with. I'm always looking into the documentation because the NetStream events are not accessible via constants.

 

The following scenario. I build a video player with LoaderMax and I want to display a loader icon while buffering the video. Now what happens when the buffer is empty and the video still loading. If I didn't overlooked something I would have to do the following:

 

_videoLoader.netStream.addEventListener( NetStatusEvent.NET_STATUS, handleNetStatus );
private function handleNetStatus( event:NetStatusEvent ):void
{
if( event.info.level == "status" )
{
	switch( event.info.code )
	{
		case "NetStream.Buffer.Empty":
			// show loader icon
			break;
		case "NetStream.Buffer.Full":
			// hide loader icon
			break;
	}
}
}

 

I think it would be nicer if it could be done like this:

 

_videoLoader.addEventListener( NetStreamEvent.STATUS_BUFFER_EMPTY, handleNetStatus );
_videoLoader.addEventListener( NetStreamEvent.STATUS_BUFFER_FULL, handleNetStatus );
private function handleNetStatus( event:NetStreamEvent ):void
{
switch( event.type )
{
	case NetStreamEvent.STATUS_BUFFER_EMPTY:
		// show loader icon
		break;
	case NetStreamEvent.STATUS_BUFFER_FULL:
		// hide loader icon
		break;
}
}

 

Looks way cleaner, doesn't it. And there is no need to look up any event strings from the docs. You immediately get what is being done. In my opinion there is a lot of potential regarding the netStream to make things a lot easier. What do you think?

Link to comment
Share on other sites

Yep, VideoLoader already dispatches VIDEO_BUFFER_EMPTY and VIDEO_BUFFER_FULL events :)

 

_videoLoader.addEventListener( VideoLoader.VIDEO_BUFFER_EMPTY, handleNetStatus );
_videoLoader.addEventListener( VideoLoader.VIDEO_BUFFER_FULL, handleNetStatus );

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...