castlabs / dashas

MPEG-DASH player written in ActionScript
http://castlabs.github.io/dashas
Other
102 stars 30 forks source link

OSMF plugin only works with Strobe Media Player? #37

Closed neilrackett closed 9 years ago

neilrackett commented 9 years ago

Getting the plugin to work with provided SMP is easy and works really well, but the plugin doesn't seem to work with bespoke OSMF media players.

For example, the following is the source code for a simple OSMF player (built with the latest official OSMF SWC) that should work as a drop-in replacement for the SMP in the demo page, but it doesn't work; you can see that everything is loading, but it always results in playbackError when a DASH URL is used.

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import org.osmf.elements.VideoElement;
    import org.osmf.events.MediaFactoryEvent;
    import org.osmf.events.MediaPlayerStateChangeEvent;
    import org.osmf.media.MediaPlayerSprite;
    import org.osmf.media.URLResource;

    public class DashTest extends Sprite
    {
        public var player:MediaPlayerSprite;

        public function DashTest()
        {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        protected function init(event:Event):void
        {           
            player = new MediaPlayerSprite();
            player.width = stage.stageWidth;
            player.height = stage.stageHeight;
            player.mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, stateChangeHandler);
            player.mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, pluginHandler);
            player.mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD_ERROR, pluginHandler);
            player.mediaFactory.loadPlugin(new URLResource(loaderInfo.parameters.plugin_DashPlugin));

            addChild(player);
        }

        protected function stateChangeHandler(event:MediaPlayerStateChangeEvent):void
        {
            // event.state outputs "playbackError"
        }

        protected function pluginHandler(event:MediaFactoryEvent):void
        {
            if (event.type == MediaFactoryEvent.PLUGIN_LOAD)
            {
                var resource:URLResource = new URLResource(loaderInfo.parameters.src);

                // UPDATE: To fix this code, simple replace:
                // var element:VideoElement = new VideoElement(resource); // ... with
                var element:MediaElement = player.mediaFactory.createMediaElement(resource);

                player.media = element;
            }
        }
    }
}

In more complex OSMF players, I've tried embedding the plugin both as a SWF and as a class, but receive the following error, which occurs when OSMF is unable to populate the streamName property of a NetStreamOptions object before playback:

RangeError: Error #1125: The index 0 is out of range 0. at org.osmf.net::NetStreamPlayTrait/playStateChangeStart()

Have you modified the version of OSMF you've included with SMP (I noted that there was a mention of it being "tidied up" in response to a previous issue)? Or are there additional configuration options that need to be set before using the plugin with a bespoke player?

All help and/or examples gratefully received!

neilrackett commented 9 years ago

OK, so the solution was embarrassingly simple: I just needed to use player.mediaFactory.createMediaElement(resource); instead of new VideoElement(resource); to resolve the issues in the source code above.

(Though I'm still not sure what the issues are in the more complex players)

chartelt commented 9 years ago

Simply nice that you provided this feedback. Thanks!