actionscript-3flashflash-builderosmf

Use NetStream with MediaPlayerSprite in OSMF


Maybe what I'm trying is not possible or has no sense but is a requirement.

The thing is easy.

I've used OSMF for writing a video player. All works fine if I create a MediaPlayerSprite and set it's resource with URLResource. I can play any supported http or rtmp streaming video (flv, mp4, mpeg, etc...).

But now I need to use NetStream class for using some of its methods.

The times that I've used NetStream class were for streaming video with the flash Video object but now I want to use it with OSMF instead.

So my question is, is possible to use MediaPlayerSprite (and all of OSMF features) but also have the capability to use NetStream methods (like attachNetStream in particular) to control the video played in the MediaPlayerSprite object?

Yes that's it...Use attachNetStream with MediaPlayerSprite for handling the video.

Why? I'm using a subclass of NetStream provided by the client that works with flash Video object and of course not with MediaPlayerSprite and if I use any of the client's class methods, obviously I get a crash.

So how would you guys achieve that? Extending any class? Modifying OSMF build?

Thanks a lot in advance.


Solution

  • Finally got working. I post the anser in case anyone needs to do the same.

    I assuming you will use a MediaPlayer or MediaPlayerSprite for loading a video. So we create our video object in stage and then using VideoElement load data.

    var mps:MediaPlayerSprite = new MediaPlayerSrpite();
    var resource:URLResource = new URLResource("http://example.com");
    mps.media = new VideoElement(resource, new NetLoader());
    

    But for using your custom NetStream and NetConnection in the OSMF fwk you need to obviously override createNetStream method of NetLoader class and the create method of the NetConnectionFactoryBase.

    Then you could use any MediaPlayer event or method to control the playback like

    mps.mediaPlayer.play();