1 Reply Latest reply on Feb 28, 2010 11:50 PM by Edwin van Rijkom

    MetadataWatcher executes callback when watch() is called

    trundell Level 1

      I'm developing a plugin that watches the current MediaElement for changes to a particular namespace's metadata.  The corresponding Facet is not actually created until some time after playback of the media has begun.  Therefore I'm trying to use a MetadataWatcher to tell me when this namespace and corresponding metadata becomes available.

       

      However, it appears that the mere act of watching the namespace causes the callback function to be executed.  It's possible to work around this by ignoring callback executions with a null value, but it's annoying to have to do so.  Here's a couple snippets from my plugin to demonstrate what I'm doing...

       

      private var watcher:MetadataWatcher;
      
      override protected function processLoadStateChange(state:String):void {
           if (loadState == LoadState.READY) {
                trace("creating watcher...");
                watcher = MetadataUtils.watchFacet(metadata, new URL("http://example.com/metadata"), onMetadataChange);
                trace("watching...");
                watcher.watch();
                trace("done calling watch");
           }
      }
      
      private function onMetadataChange(val:Object):void {
           trace("EXECUTED CALLBACK: "+val);
      }
      

       

      This leads to the following trace...

       

      creating watcher...

      watching...

      EXECUTED CALLBACK: null

      done calling watch

       

      This seems like a bug in MetadataWatcher to me.  Or is there some reason why calling watch() should always execute the callback?

        • 1. Re: MetadataWatcher executes callback when watch() is called
          Edwin van Rijkom Level 2

          Hi Trevor,

           

          Thank you for your feedback.

           

          The initial change event is triggered because on internal use we found that the change handling routine would usually have to be invoked manually right after adding a watcher in order to set initial values. Having the change watcher dispatch on starting to watch saves adding a manual call to the change handler.

           

          I've extended the watch method with an optional 'dispatchInitialChangeEvent' boolean (true by default) so this behavior can be circumvented if so desired.

           

          Cheers,

          Edwin