2 Replies Latest reply on Mar 28, 2012 5:02 AM by DavidKomer

    CloudFiles, Akamai, SMIL

    DavidKomer

      I've been looking through the plugin example, older OSMF examples, etc. and I haven't yet been able to piece together a working player which uses SMIL and the Akamai HDNetwork (via Rackspace Cloudfiles).

       

      The SMIL file does play properly when tested via flowplayer or my old custom-built version, which used HDCore.

       

      Here's the basic code I've tried, to no avail:

       

       

      package

      {

                import com.akamai.osmf.AkamaiBasicStreamingPluginInfo;

       

                import flash.display.Sprite;

                import flash.events.EventDispatcher;

       

                import org.osmf.containers.MediaContainer;

                import org.osmf.elements.VideoElement;

                import org.osmf.events.MediaFactoryEvent;

                import org.osmf.media.DefaultMediaFactory;

                import org.osmf.media.MediaElement;

                import org.osmf.media.MediaFactory;

                import org.osmf.media.MediaPlayer;

                import org.osmf.media.MediaResourceBase;

                import org.osmf.media.PluginInfo;

                import org.osmf.media.PluginInfoResource;

                import org.osmf.media.URLResource;

                import org.osmf.net.DynamicStreamingResource;

       

                public class VP_REGULAR extends Sprite

                {

                          private var mediaContainer:MediaContainer = null;

                          private var mediaPlayer:MediaPlayer = null;

                          private var smilLoader:SmilLoader = null;

                          private var mediaElement:MediaElement = null;

       

                          public function VP_REGULAR()

                          {

                                    super();

       

        //this.src = "http://c11412232.r32.stream.cf2.rackcdn.com/test/mbrtest/makingfriends_trailer_akamai_h264 _768x432_800kbps.mp4";

        this.src = "http://localhost/SimplePlayer/test.smil";

                          }

       

                          public function set src(str:String) {

       

        //Clear existing

                                    stop();

                                    mediaPlayer = null;

                                    if(mediaContainer != null) {

                                              removeChild(mediaContainer);

                                    }

                                    mediaContainer = null;

                                    mediaElement = null;

       

                                    if(smilLoader != null) {

                                              smilLoader.removeEventListener(ObjEvent.COMPLETE, smilLoaded);

                                              smilLoader.close();

                                              smilLoader = null;

                                    }

                                    if(str.indexOf('.smil') == -1) {

                                              loadSingleMedia(str);

                                    } else {

                                              loadSmil(str);

                                    }

                          }

       

                          public function stop() {

                                    if(mediaPlayer != null) {

                                              mediaPlayer.stop();

                                    }

                          }

       

                          private function loadSingleMedia(str:String) {

                                    var mediaFactory:MediaFactory = new DefaultMediaFactory();

                                    var mediaResource:URLResource = new URLResource(str);

                                    mediaElement = mediaFactory.createMediaElement(mediaResource);

       

                                    playMediaElement();

                          }

       

                          private function loadSmil(str:String) {

                                    smilLoader = new SmilLoader();

                                    smilLoader.addEventListener(ObjEvent.COMPLETE, smilLoaded);

                                    smilLoader.load(str);

                          }

       

                          private function smilLoaded(evt:ObjEvent) {

        trace('SMIL LOADED!');

                                    mediaElement = new VideoElement(evt.obj.resource);

                                    loadAkamaiPlugin();

                          }

       

                          private function loadAkamaiPlugin():void

                          {

                                    var mediaFactory:MediaFactory = new DefaultMediaFactory();

                                    var pluginResource:MediaResourceBase = new PluginInfoResource(new AkamaiBasicStreamingPluginInfo());

       

                                    mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, onAkamaiPluginLoaded);

                                    mediaFactory.loadPlugin(pluginResource);

                          }

       

                          private function onAkamaiPluginLoaded(evt:MediaFactoryEvent) {

        trace('AKAMAI PLUGIN LOADED!');

                                    playMediaElement();

                          }

       

                          private function playMediaElement() {

       

                                    if(mediaPlayer == null) {

                                              mediaPlayer = new MediaPlayer();

                                    }

       

                                    if(mediaContainer == null) {

                                              mediaContainer = new MediaContainer();

                                              addChild(mediaContainer);

                                    }

       

                                    mediaContainer.addMediaElement(mediaElement);

                                    mediaPlayer.media = mediaElement;

       

                                    for each(var foo:* in mediaElement.metadata) {

                                              trace(foo, mediaElement.metadata[foo]); //Nothing

                                    }

       

                          }

                }

      }

       

       

      and smilLoader, truncated for brevity (xmlLoader is just a class which loads the XML and ObjEvent is just an Event which can pass Objects)

       

       

      package

      {

                import flash.events.EventDispatcher;

                import flash.net.URLRequest;

       

                import org.osmf.net.DynamicStreamingItem;

                import org.osmf.net.DynamicStreamingResource;

       

                public class SmilLoader extends EventDispatcher

                {

                          private var xmlLoader:XMLLoader = null;

                          private var _resource:DynamicStreamingResource = null;

       

                          public function SmilLoader()

                          {

                          }

       

                          public function close():void {

                                    if(xmlLoader != null) {

                                              xmlLoader.removeEventListener(ObjEvent.COMPLETE, XMLLoaded);

                                              xmlLoader.closeAll();

                                              xmlLoader = null;

                                    }

                          }

       

                          public function load(str:String) {

                                    close();

       

                                    _resource = null;

       

                                    xmlLoader = new XMLLoader();

                                    xmlLoader.addEventListener(ObjEvent.COMPLETE, XMLLoaded);

                                    xmlLoader.loadXML(new URLRequest(str));

                          }

       

                          private function XMLLoaded(evt:ObjEvent) {

                                    var headNode:XML;

                                    var bodyNode:XML;

                                    var xmlNode:XML;

                                    var videoNode:XML;

                                    var videoObj:Object;

                                    var httpBase:String = null;

                                    var videos:Array = [];

                                    var item:DynamicStreamingItem;

                                    var vector:Vector.<DynamicStreamingItem> = new Vector.<DynamicStreamingItem>();

       

                                    for each(xmlNode in evt.target.xmlData.elements()) {

                                              switch(xmlNode.localName().toLowerCase()) {

                                                        case 'head': headNode = xmlNode; break;

                                                        case 'body': bodyNode = xmlNode; break;

        default: break;

                                              }

                                    }

       

                                    if(headNode.length()) {

                                              for each(xmlNode in headNode.elements()) {

                                                        if(xmlNode.localName().toLowerCase() == 'meta') {

                                                                  if(xmlNode.@name.toString().toLowerCase() == 'httpbase') {

                                                                            httpBase = xmlNode.@content.toString();

                                                                  }

                                                        }

                                              }

                                    }

       

                                    if(httpBase != null) {

                                              for each(xmlNode in bodyNode.elements()) {

                                                        if(xmlNode.localName().toLowerCase() == 'switch') {

                                                                  for each(videoNode in xmlNode.elements()) {

                                                                            if(videoNode.localName().toLowerCase() == 'video') {

                                                                                      videos.push({src: videoNode.@src.toString(), bitrate: videoNode.attribute('system-bitrate').toString()});

                                                                            }

                                                                  }

                                                        }

                                              }

       

                                    }

       

                                    if(videos.length > 0) {

                                              _resource = new DynamicStreamingResource(httpBase);

       

                                              for each(videoObj in videos) {

                                                        vector.push(new DynamicStreamingItem (videoObj.src, videoObj.bitrate));

                                              }

       

                                              _resource.streamItems = vector;

                                              dispatchEvent(new ObjEvent(ObjEvent.COMPLETE, {resource: _resource}));

                                    } else {

        trace('ERROR IN FILE!');

                                    }

       

                                    close();

                          }

                }

      }

       

       

      The trace is fine:

       

       

      SMIL LOADED!

      AKAMAI PLUGIN LOADED!

       

       

      Just no video...

       

      Thanks in advance!

        • 1. Re: CloudFiles, Akamai, SMIL
          DavidKomer Level 1

          Oh interesting... it seems to work with rtmp... what do I change to make it work with http?

          • 2. Re: CloudFiles, Akamai, SMIL
            DavidKomer Level 1

            didn't realize there already existed a SMIL plugin... here's my updated code, which still doesn't work (but does work when using a rtmp-powered smil file):

             

             

            package

            {

                      import flash.display.Sprite;

                      import flash.events.EventDispatcher;

             

                      import com.akamai.osmf.AkamaiBasicStreamingPluginInfo;

                      import org.osmf.containers.MediaContainer;

                      import org.osmf.elements.VideoElement;

                      import org.osmf.events.DynamicStreamEvent;

                      import org.osmf.events.MediaFactoryEvent;

                      import org.osmf.events.MediaPlayerStateChangeEvent;

                      import org.osmf.media.DefaultMediaFactory;

                      import org.osmf.media.MediaElement;

                      import org.osmf.media.MediaFactory;

                      import org.osmf.media.MediaPlayer;

                      import org.osmf.media.MediaResourceBase;

                      import org.osmf.media.PluginInfo;

                      import org.osmf.media.PluginInfoResource;

                      import org.osmf.media.URLResource;

                      import org.osmf.net.DynamicStreamingResource;

                      import org.osmf.smil.SMILPluginInfo;

             

                      public class VP_REGULAR extends Sprite

                      {

                                private var mediaContainer:MediaContainer = null;

                                private var mediaPlayer:MediaPlayer = null;

                                private var mediaElement:MediaElement = null;

                                private var mediaFactory:MediaFactory = null;

                                private var _src:String = null;

                                private var _pluginsToLoad:Array = null;

             

                                public function VP_REGULAR()

                                {

                                          super();

             

              this.src = "http://tjandpals.com/xmlfiles/streams/hdnetwork/promo/video_tour.smil";

              //this.src = "http://mediapm.edgesuite.net/ovp/content/demo/smil/elephants_dream.smil";

                                }

             

                                public function set src(str:String) {

                                          if(_src == str || str == null) {

              return;

                                          }

             

                                          close();

             

                                          _src = str;

             

                                          mediaFactory = new DefaultMediaFactory();

                                          loadPlugins([new AkamaiBasicStreamingPluginInfo(), new SMILPluginInfo()]);

             

                                }

                                public function close() {

                                          stop();

             

                                          if(mediaPlayer != null) {

                                                    mediaPlayer.removeEventListener(MediaPlayerStateChangeEvent.MEDIA_PLA YER_STATE_CHANGE, playerStateChange);

                                                    mediaPlayer.removeEventListener(DynamicStreamEvent.SWITCHING_CHANGE, dynamicStreamChange);

                                          }

             

                                          if(mediaContainer != null) {

                                                    removeChild(mediaContainer);

                                          }

             

                                          mediaPlayer = null;

                                          mediaContainer = null;

                                          mediaElement = null;

                                          mediaFactory = null;

                                          _pluginsToLoad = null;

                                          _src = null;

                                }

             

                                public function stop() {

                                          if(mediaPlayer != null) {

                                                    mediaPlayer.stop();

                                          }

                                }

             

                                private function loadPlugins(__pluginsToLoad:Array = null) {

                                          if(__pluginsToLoad != null) {

                                                    _pluginsToLoad = __pluginsToLoad;

                                          }

             

                                          if(_pluginsToLoad.length) {

                                                    loadPlugin(_pluginsToLoad.shift());

                                          } else {

                                                    allPluginsLoaded();

                                          }

                                }

                                private function loadPlugin(source:PluginInfo):void {

                                          var pluginResource:MediaResourceBase;

             

                                          pluginResource = new PluginInfoResource(source);

                                          loadPluginFromResource(pluginResource);

                                }

             

                                private function loadPluginFromResource(pluginResource:MediaResourceBase):void {

                                          mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, onPluginLoaded);

                                          mediaFactory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadFailed);

                                          mediaFactory.loadPlugin(pluginResource);

                                }

             

                                private function onPluginLoaded(event:MediaFactoryEvent):void {

              trace("Plugin loaded");

                                          loadPlugins();

                                }

             

                                private function onPluginLoadFailed(event:MediaFactoryEvent):void {

              trace("Could not load Plugin");

                                          loadPlugins();

                                }

             

                                private function allPluginsLoaded():void {

              trace('All plugins loaded!');

                                          loadMedia();

                                }

             

                                private function loadMedia() {

                                          var mediaResource:URLResource = new URLResource(_src);

                                          mediaElement = mediaFactory.createMediaElement(mediaResource);

             

                                          trace(mediaElement);

             

                                          playMediaElement();

                                }

             

                                private function playMediaElement() {

             

                                          if(mediaPlayer == null) {

                                                    mediaPlayer = new MediaPlayer();

                                                    mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER _STATE_CHANGE, playerStateChange);

                                                    mediaPlayer.addEventListener(DynamicStreamEvent.SWITCHING_CHANGE, dynamicStreamChange);

             

                                          }

             

                                          if(mediaContainer == null) {

                                                    mediaContainer = new MediaContainer();

                                                    addChild(mediaContainer);

                                          }

             

                                          mediaContainer.addMediaElement(mediaElement);

                                          mediaPlayer.media = mediaElement;

             

             

                                }

             

                                private function playerStateChange(evt:MediaPlayerStateChangeEvent) {

                                          trace(evt.state);

                                }

             

                                private function dynamicStreamChange(evt:DynamicStreamEvent) {

                                          var player:MediaPlayer = evt.target as MediaPlayer;

                                          trace('switched dynamic stream to:', player.currentDynamicStreamIndex);

                                }

                      }

            }