1 Reply Latest reply on May 6, 2011 4:58 AM by Mihai Teleru

    Simple plugin to play custom media

    ferrybaltimor

      Hi,

       

      I'm working on a plugin to load custom media depending on the user ip. I'm a newbie on osm plugin development and I'm unable to find a simple example as base in order to do what I need.

       

      I just write the plugin info and  I add this to the media creation function in order to overwrite the media to be played but it doesn't work.

       

       

      private function mediaElementCreationFunction():MediaElement{


                   trace('media element creation function');
                  
                   var urlResource:URLResource = new URLResource("http://nice264.com/test.mp4");
                   var netLoader:NetLoader = new NetLoader();
                  
                  
                   return new VideoElement(urlResource,netLoader);

      }

       

      What would be the correct way to do it?

       

       

       

       

       

      package
      {
         
          import org.osmf.elements.VideoElement;
          import org.osmf.media.MediaElement;
          import org.osmf.media.MediaFactoryItem;
          import org.osmf.media.MediaFactoryItemType;
          import org.osmf.media.MediaResourceBase;
          import org.osmf.media.PluginInfo;
          import org.osmf.media.URLResource;
          import org.osmf.metadata.Metadata;
          import org.osmf.net.NetConnectionFactory;
          import org.osmf.net.NetLoader;
         
             
          public class OSMFNice264PluginInfo extends PluginInfo
          {
             
                 
             
              public function OSMFNice264PluginInfo()
              {
                  var items:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
                 
         
                 
                  // Create the MediaFactoryItem and add to our list of items.
                  var item:MediaFactoryItem = new MediaFactoryItem
                      ( "com.osmf.VideoElement"
                          , canHandleResourceFunction
                          , mediaElementCreationFunction
                          , MediaFactoryItemType.STANDARD
                      );
                 
         
                  items.push(item);
                  // Pass the list to the base class.
                  super(items);
              }
             

       

              private function canHandleResourceFunction(resource:MediaResourceBase):Boolean
              {
                  var result:Boolean = false;
                  // Only return true if the resource is an URLResource...
                  var urlResource:URLResource = resource as URLResource;
                  if (urlResource != null)
                  {
                      // ... and if the URL starts with "rtmp".
                      result = urlResource.url.indexOf("rtmp") == 0;
                     
                  //    urlResource
                     
                  }
                 
             
                 
                  return true;
              }
             

              private function mediaElementCreationFunction():MediaElement
              {
                  trace('media element creation function');
                 
                  var urlResource:URLResource = new URLResource("http://nice264.com/test.mp4");
                  var netLoader:NetLoader = new NetLoader();
                 
                 
                  return new VideoElement(urlResource,netLoader);
                 
             
              }
             
             
              private function creationNotificationFunction(media:MediaElement):void
              {
         
                  trace('created media element');       
                  var url:String = (media.resource as URLResource).url;
                 
                  trace( url );
              }

       

          }
      }

        • 1. Re: Simple plugin to play custom media
          Mihai Teleru

          Hello,

           

          I think it would be very useful for you to take a look at the plug-in developer's guide. Check out the Using a plug-in and Building a plug-in sections.

           

          Note that in the mediaElementCreationFunction you should only return a media element without any parameters. This function is used to tell the player what kind of media element you want. Basically, you can choose between VideoElement, AudioElement, ImageElement etc.

          The resource should not be set here, but in the player code.

           

          Also, the canHandleResourceFunction should return a boolean telling the player whether the plug-in can handle the specific resource. In your code, the function only returns true if the stream is RTMP.

          If you want the plug-in to be able to handle any type of resources you should always return true.

           

          Basically, a standard plug-in is used to specify the type of the media element you want to be used for a specific media resource.

           

          What you're looking for seems to be a way to actually play a different resource based on the user. For this, I recommend focusing on the proxy plug-in type.

          You'll have to define a custom media element which extends the ProxyElement class which changes the media resource to be played.

          In the mediaElementCreation function you'll return a MyProxyElement() (the name you'll give to the media element class).

           

          Let me know if you have any other questions.

          Mihai.