3 Replies Latest reply: Sep 27, 2012 2:06 AM by Gaius Coffey RSS

    MediaFactory and Plugins


      I have a working OSMF player that I'm trying to use plugins to expand the features and I need some clarification on how the factory works.


      I have some code like this


      _mediaElement = _mediaFactory.createMediaElement( _dynResource );

      captionMetadata = new TimelineMetadata(_mediaElement);

      _mediaElement.addMetadata(CaptioningPluginInfo.CAPTIONING_TEMPORAL_METADATA_NAMESPACE, captionMetadata);

      captionMetadata.addEventListener(TimelineMetadataEvent.MARKER_TIME_REACHED, captionHandler);


      // _mediaElement.smoothing = true;


      _mediaPlayer.media = _mediaElement;


      Before I used the factory to add the captioning data I was just creating a VideoElement allowing me to do the smoothing that is now commented out. I thought that the factory would create a MediaElement which i could then cast to a VideoElement to be able to turn on smoothing but instead the Factory is returning a org.osmf.captioning.media.CaptioningProxyElement which will not cast to a VideoElement. I plan on adding more plugins and it doesn't feel correct to have multiple levels of casting especially since the the experiments I've tried on that front seem to break the listeners on the captioning.

        • 1. Re: MediaFactory and Plugins
          TheRossman Community Member

          CaptioningProxyElement.proxiedElement should be your original media element (VideoElement in your case) i guess?


          I can't guarantee this would work, but maybe:


          if( _mediaElement is ProxyElement )

              (_mediaElement.proxiedElement as VideoElement).smoothing = true;


          Hope that helps,


          • 2. Re: MediaFactory and Plugins
            Gaius Coffey Community Member


            It looks like you are adding the metadata directly to the MediaElement?

            I thought the thing to do was to add the metadata to the URLResource before using MediaFactory to generate the MediaElement? That way, the element is properly populated without the need for any intervention.


            • 3. Re: MediaFactory and Plugins
              Gaius Coffey Community Member

              Oops... But I didn't answer the question!


              What I did (which is nasty, but it is effective) is to subclass the DefaultMediaFactory and modify the resolveItems function so that it will recurse down to video and set it there.

              EG: Something like:



              protected function smoothElement(initElement:MediaElement):void {

              var element:MediaElement = recurseForProxies(initElement);

              if(!element) {

                trace("Oops! Nothing to smooth. "+initElement);



              if( element is VideoElement )


                VideoElement( element ).smoothing = smoothing;

                VideoElement( element ).deblocking = deblocking;


                trace("\t\t(Video smoothed.)");

              } else if( element is ImageElement) {

                ImageElement( element ).smoothing = smoothing;



              protected function recurseForProxies(element:MediaElement):MediaElement {

              if(element is ProxyElement) return recurseForProxies((element as ProxyElement).proxiedElement);

              if(element is SerialElement) return recurseForProxies((element as SerialElement).currentChild);

              return element;