17 Replies Latest reply on Jul 6, 2011 9:12 AM by AmigoCaracas

    I need to load the video currentTime and duration in a swf plugin

    AmigoCaracas Level 1

      Hi

      I am really lost

      Sorry to open a new discussion, but I need help

      I am really lost

      I can connect the video main project to a dynamic swf plugin, But I need to get information like currentTime, and duration of the video, and I can't

      The problem is me, I can't understand how to do that

      I don't want to use metadata to send all the information from the video player to the plugin, I need to get it directly in the plugin

      Please, anybody has any example?

      I have uploaded what I have till now, but I really need to do this, please

      Mykola3296 was explaining me very good, and very good person, but I still can't understand and can't make it works

      the problem is me, I need to understand like step by step of how to do that.

       

      I dont pretend that some one do what I want to do, but if anybody can explain me or if anybody can just get one data like currentTime or duation, then I can understand and get all the rest information that I need to get

       

      I was reading materials, but I cant find a really easy tutorial of how to get that information from the video in a dynamic plugin (swf)

       

      the main project video player: http://www.paintballpark.it/videos/PluginCDN.rar

      the plugins :  http://www.paintballpark.it/videos/plugins.rar

      I really need help

      thanks a lot to everybody

        • 1. Re: I need to load the video currentTime and duration in a swf plugin
          Mykola3296 Level 2

          hi

          you do not actually need to pass all the data through metadata.

          you just need to MARK one element as a  main content so your plugin to know from which element to get traits.

          from that point you use a notification function in your plugininfo tocheck every created element if it is a CONTENT one.

          as soon as your element arrives here you go

          you get time trait and watch it the way i have shown you.

           

          another way is registering a proxy element plugin for each media resource type that might be interesting for you. through this way you get your element created and provided a reference to main content element.

          override public function set proxiedelemment is a point you get reference to main contenbegin watching a timetrait at this point.

          1 person found this helpful
          • 2. Re: I need to load the video currentTime and duration in a swf plugin
            AmigoCaracas Level 1

            Thanks again

            You can't imagine how I am searching and searchin in google

            I will keep searching

            thaks again

            I hope I can get this working soon

            Is driving me crazy

            • 3. Re: I need to load the video currentTime and duration in a swf plugin
              AmigoCaracas Level 1

              with this code, I am sending metadata like string, but once I load the video, I want to send metadata from that video, but I cant
              the pluging doesnt detect my video metadata, can You help me?

              package
              {
              import org.osmf.events.MediaFactoryEvent;
              import org.osmf.media.DefaultMediaFactory;
              import flash.events.MouseEvent;
              import flash.display.Graphics;
              import org.osmf.events.PlayEvent;
              import flash.display.Sprite;
              import org.osmf.containers.MediaContainer;
              import org.osmf.media.DefaultMediaFactory;
              import org.osmf.media.MediaElement;
              import org.osmf.media.MediaFactory;
              import org.osmf.media.MediaPlayer;
              import org.osmf.media.URLResource;
              import org.osmf.metadata.Metadata;
              import org.osmf.events.TimeEvent;
              import org.osmf.traits.TimeTrait;
              import org.osmf.events.MediaElementEvent;
              import org.osmf.traits.MediaTraitType;
              import flash.utils.Timer;
              import flash.events.TimerEvent;
              import org.osmf.traits.TraitEventDispatcher



              //01jul
              import org.osmf.net.NetLoader;
              //
              [SWF(width="640", height="352")]
              public class PluginCDN extends Sprite
              {
                private var timer:Timer;
                private var _tt:TimeTrait;
                protected var factory:MediaFactory;
                //01jul
                private var _netLoader:NetLoader;
                //
               
                public function PluginCDN()
                {
                

                
                var factory:MediaFactory = new DefaultMediaFactory();
                factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD, onPluginLoad);
                factory.addEventListener(MediaFactoryEvent.PLUGIN_LOAD_ERROR, onPluginLoadError);
               

                var resourcePI:URLResource = new URLResource("http://localhost/plugins/SimpleVideoPluginInfo.swf");//30jun


               
               
                resourcePI.addMetadataValue("username", "Alex");
                var bytesTotales:Number = 030;//mediaPlayer.bytesTotal;
                //resourcePI.addMetadataValue("password", 30);

               
                factory.loadPlugin(resourcePI);
               

                }

                private function onPluginLoad(event:MediaFactoryEvent):void
                {
                 trace("Plugin cargado con exito");
                
                 var container:MediaContainer = new MediaContainer();
                 addChild(container);

                 var mediaFactory:MediaFactory = new DefaultMediaFactory();

                 var resource:URLResource = new URLResource("http://mediapm.edgesuite.net/strobe/content/test/SpaceAloneHD_sounas_640_500_short.flv");

                 var mediaElement:MediaElement = mediaFactory.createMediaElement(resource);
                 container.addMediaElement(mediaElement);

                 var mediaPlayer:MediaPlayer = new MediaPlayer();
                 mediaPlayer.media = mediaElement;
              resource.addMetadataValue("password", mediaPlayer.duration); //this metadata I cant send to plugin

                 var intervalo:Timer = new Timer(1000, 0);
                 intervalo.addEventListener(TimerEvent.TIMER, enviarDatos);
                
                 function enviarDatos(event:TimerEvent):void
                 {
                 var TotalDuration:Number = mediaPlayer.currentTime;
                 trace("duracion: " + TotalDuration);
                 }

                }
               
                private function onPluginLoadError(event:MediaFactoryEvent):void
                {
                 trace('plugin load error');

                }

              }

              }

              • 4. Re: I need to load the video currentTime and duration in a swf plugin
                AmigoCaracas Level 1

                Ok


                I reached the point of sending a metadata like BytesLoaded to the plugin
                I need now to get all the information that I need, like duration and currentTime
                • 5. Re: I need to load the video currentTime and duration in a swf plugin
                  AmigoCaracas Level 1

                  In this code (taken from a ru.denivip.stats example) I cant get into the creationNotificationFunction function
                  I wrote some traces but dont want to work
                  I think this is the correct way to get information like duration and currenttime in the swf plugin
                  can anybory help me?
                  I am close to solve my problem
                  thanks

                  code:
                  package
                  {
                  import flash.events.TimerEvent;
                  import flash.utils.Timer;
                  import flash.utils.clearTimeout;
                  import flash.utils.setTimeout;
                  import flash.net.URLLoader;
                  import flash.events.Event;
                  import org.osmf.media.*;
                  import org.osmf.net.*;
                  import org.osmf.elements.VideoElement;
                  import org.osmf.media.MediaResourceBase;
                  import org.osmf.metadata.Metadata;
                  import org.osmf.media.MediaFactoryItem;
                  import org.osmf.media.URLResource;
                  import org.osmf.media.PluginInfo;
                  import org.osmf.media.MediaElement;
                  import org.osmf.events.MediaElementEvent;
                  import org.osmf.traits.MediaTraitType;
                  import org.osmf.traits.TimeTrait;
                  import org.osmf.traits.TraitEventDispatcher;
                  import org.osmf.events.TimeEvent;

                  import SimpleVideoPluginInfo;

                  import org.osmf.net.NetLoader;

                   

                  public class CDNPluginInfo extends PluginInfo
                  {
                    private var _VASTLoader:URLLoader;
                    private var username:String;
                    private var passW:Number;
                    private var userid:String;
                   
                    public const SSO_USERNAME:String = "username";
                    public const SSO_PASSWORD:String = "password";
                   

                    public static const NS:String = 'cdn'; //folder where I have the StatsTracker.as file
                   
                    public static const METADATA_USER_ID:String = 'userid';
                    private var timer:Timer;
                    private var media:MediaElement;
                    private var resourceURL:String;
                    private var userID:int;
                   
                    public function CDNPluginInfo()
                    {
                     trace("CDNPluginInfo <------ 5 jul" );
                      var items:Vector.<MediaFactoryItem> = new Vector.<MediaFactoryItem>();
                     var item:MediaFactoryItem = new MediaFactoryItem(NS, canHandleResourceFunction, mediaElementCreationFunction);
                     items.push(item);

                     super(items, creationNotificationFunction);
                    

                    }

                    private function canHandleResourceFunction(resource:MediaResourceBase):Boolean
                    {
                     return true;
                    }
                    private function mediaElementCreationFunction():MediaElement
                    {
                     return new VideoElement();
                    }
                    private function creationNotificationFunction(media:MediaElement):void
                    {
                     trace('created media element');
                    
                     var url:String = (media.resource as URLResource).url;
                     var userID:uint = media.resource.getMetadataValue(METADATA_USER_ID) as uint;
                    
                     var tracker:StatsTracker = new StatsTracker(media, url, userID);
                     trace("URL: " + url);
                     if (media.hasTrait(MediaTraitType.TIME)) {
                      trace("tracker.start()");
                      tracker.start();
                     }
                    }
                    override public function initializePlugin(resource:MediaResourceBase):void
                     {
                     var intervalo:Timer = new Timer(2000, 0);
                     intervalo.addEventListener(TimerEvent.TIMER, enviarDatos);
                     intervalo.start();
                     function enviarDatos(){
                     username = resource.getMetadataValue(SSO_USERNAME) as String;
                     passW =  resource.getMetadataValue(SSO_PASSWORD) as Number;
                     userid = resource.getMetadataValue(METADATA_USER_ID) as String;
                     //passW = resource.getMetadata(SSO_PASSWORD) as Number;
                     trace("dato: " + username + " , " + passW + " , " + userid);
                    
                     //trace("nuevo " + nuevo);
                  //  resource.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onCurrentTimeChange);
                  //   org.osmf.media.URLResource.addEventListener(TimeEvent.DURATION_CHANGE, onCurrentDurationChange);
                    
                     }
                     }
                  }
                  }

                  • 6. Re: I need to load the video currentTime and duration in a swf plugin
                    Mykola3296 Level 2

                    hi

                    why do you want to send values through metadata?

                    why don t you want to send just an element reference?

                    if you get pointer to the whole element you can request any value from it later

                    using that marker metadata you tell your plugin where the main content is

                    i think it is nuch more versatile

                    • 7. Re: I need to load the video currentTime and duration in a swf plugin
                      AmigoCaracas Level 1

                      Sorry for my english, but what do you mind with element reference?

                       

                      I supossed that is a metadata value from the video like bytestotal, and then I can get all the information

                      what do You mind with element reference?

                      do You have any example?

                      thanks

                      • 8. Re: I need to load the video currentTime and duration in a swf plugin
                        AmigoCaracas Level 1

                        Hi

                        sorry, but how can I create that element reference?

                        What do You mean with that?

                        I mean, I think that creatin a metadata I can get that "link" to the video to get all the other information, but I can't

                        Thanks for your help

                        • 9. Re: I need to load the video currentTime and duration in a swf plugin
                          Mykola3296 Level 2

                          Metadata class:

                           

                          public class MarkerMetadata extends Metadata {

                              public static const MARKER_NAMESPACE:String = "marker";

                           

                             private var _contentElement:MediaElement;

                             public function get contentElement():MediaElement {

                                return _contentElement;

                             }

                           

                             public function MarkerMetadata(contentElement:MediaElement) {

                                  _contentElement = contentElement;

                             }

                           

                          }

                           

                           

                          In main player app:

                           

                          var mainVideo:MediaElement = new VideoElement(....);

                          mainVideo.addMetadata(MarkerMetadata.MARKER_NAMESPACE, new MarkerMetadata(mainVideo));

                           

                          In plugin:

                          var markerMeta:MarkerMetadata = element.getMetadata(MarkerMetadata.MARKER_NAMESPACE) as MarkerMetadata;

                          if (null != markerMeta) {

                               var mainContent:MediaElement = markerMeta.contentElement;

                              //Here is your main video reference

                          }

                          1 person found this helpful
                          • 10. Re: I need to load the video currentTime and duration in a swf plugin
                            AmigoCaracas Level 1

                            wow

                             

                            thanks a lot for the answer Mykola

                             

                            You are great

                             

                            Updated:

                            1 questions:

                             

                            in main player app:

                             

                            var mainVideo:MediaElement = new VideoElement(....); <<<<<<<<  //(....) this I have to change for my video flv?
                            mainVideo.addMetadata(MarkerMetadata.MARKER_NAMESPACE, new MarkerMetadata(mainVideo));

                            and I get the followin error:

                            "access to undefined property MarkerMetadata"

                            do you know why is this?

                             

                            and once is done, how can I call for example the currentTime or duration?
                            I suppose I must listener for the metadata for each property (like duration and so) that I want to get, no?
                            thanks again

                             

                            as I understand, here:
                            mainVideo.addMetadata(MarkerMetadata.MARKER_NAMESPACE, new MarkerMetadata(mainVideo));
                            the word MarkerMetadata means the MarkerMetadata file that is in AS?
                            in that case I must write at the main player app this:
                            import MarkerMetadata?

                            and in that case, the player app and the plugin will access to that AS file, right?

                            thanks again

                            • 11. Re: I need to load the video currentTime and duration in a swf plugin
                              Mykola3296 Level 2

                              1) Move MarkerMetadata to separate library available for both applications in the same domain

                              Alternatively, use a basic metadata class.

                               

                              In main app:

                              var meta:Metadata = new Metadata()

                              meta.addValue("contentElement", element);

                              element.addMetadata("marker", meta);

                               

                              In plugin:

                              var meta:Metadata = element.getMetadata("marker") as Metadata;

                              if (null != meta) {

                                   content = meta.getValue("contentElement") as MediaElement;

                                   if (null != content) {

                                        ................

                                   }

                              }

                               

                              This way you don't need any new class and library

                               

                              2) To get totalTime you need to obtain timetrait from your referenced content element

                              TimeTrait has all information you need

                              • 13. Re: I need to load the video currentTime and duration in a swf plugin
                                AmigoCaracas Level 1

                                oops

                                I am getting this error:

                                Error #1009: Cannot access a property or method of a null object reference.

                                 

                                how can I know if I am sending the right element?

                                I think that is the problem

                                • 14. Re: I need to load the video currentTime and duration in a swf plugin
                                  AmigoCaracas Level 1

                                  hi
                                  Sorry
                                  I modified to:
                                     var meta:Metadata = new Metadata()
                                     meta.addValue("contentElement", resourcePI);
                                     resourcePI.addMetadataValue("marker", meta);

                                  and in plugin:
                                     var meta:Metadata = resource.getMetadataValue("marker") as Metadata;
                                     trace("----------> " + meta);  //<<---- this is working good
                                     //
                                     if (null != meta) {
                                           var content = meta.getValue("contentElement") as MediaElement;
                                           if (null != content) {
                                         trace("cargado el metadata"); //<<--- this is not working
                                              // ................
                                           }
                                     }

                                  is that ok, or I cant use addMetadataValue and getMetadataValue?

                                  • 15. Re: I need to load the video currentTime and duration in a swf plugin
                                    AmigoCaracas Level 1

                                    well is still not working
                                    in the main app I write:
                                       var meta:Metadata = new Metadata()
                                       meta.addValue("contentElement", mediaElement);
                                       mediaElement.addMetadata("marker", meta);
                                    is that ok?
                                    and in the plugin I write:
                                       var meta:Metadata = media.getMetadata("marker") as Metadata;
                                       trace("----------> " + meta);
                                       if (null != meta) {
                                          var contenido = meta.getValue("contentElement") as MediaElement;
                                             if (null != contenido) {
                                           trace("cargado el metadata");
                                             }else {
                                           trace("no cargado");
                                          }
                                       }

                                    but the error that I get is:
                                    cannot access a property or method of a null object reference

                                    what I am doing wrong?

                                     

                                    in the main app I have:

                                    I created this var to load the plugin:
                                    var resourcePI:URLResource = new URLResource("http://localhost/plugins/SimpleVideoPluginInfo.swf");
                                    then, if I try to write this:
                                    resourcePI.addMetadata("marker", meta);
                                    I cant, and then flashbuilder tell me that I have to use resourcePI.addMetadataValue("marker", meta);

                                     

                                    Message was edited by: AmigoCaracas

                                    • 16. Re: I need to load the video currentTime and duration in a swf plugin
                                      AmigoCaracas Level 1

                                      Its working

                                      Thanks Mykola

                                      Its working now

                                      I need now to get the timetrait

                                      But now the element is referenced

                                      Thanks again

                                      • 17. Re: I need to load the video currentTime and duration in a swf plugin
                                        AmigoCaracas Level 1

                                        Thanks again Mykola

                                        I am working with the traits and till now is everything working ok

                                        What I want is that at the same time that I am working with the player, understand how the OSMF is working

                                        You are great and You explain good

                                        I dont know why is sometimes dificult to understand, but You are a good Master

                                        Thanks again