<?xml version="1.0" encoding="utf-8"?>
<s:VideoPlayer xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx"
               implements="de.dtele.ui.components.viewer.IResourceViewer"
               width="100%"
               height="100%"
               skinClass="de.dtele.ui.components.skins.VideoResourceViewerSkin"
               pauseWhenHidden="false"
               add="onAdd(event)"
               remove="onRemove(event)">
  
  <fx:Metadata>
    /**
     * Allows for viewing video resources
     * 
     * By default video playback is limited to the
     * codecs supported by the Adobe Flash Player.
     * 
     * @see http://kb2.adobe.com/cps/402/kb402866.html List of codecs supported by Adobe Flash Player
     * 
     * @author Mathias Brodala
     */
  </fx:Metadata>

  <fx:Script>
    <![CDATA[
      import de.dtele.data.IResource;
      
      import mx.events.FlexEvent;
      
      public function view(resource:IResource):void {
        
        this.source = resource.fullUrl;
        
        if (this.videoObject) {
          
          // Enable video smoothing upon scaling
          this.videoObject.smoothing = true;
        }
        
        //var player:org.osmf.media.MediaPlayer = this.videoDisplay.mx_internal::videoPlayer;
        
        //this.addEventListener(VideoEvent.READY, this.onReady);
        
        this.dispatchEvent(new Event(Event.COMPLETE));
      }
      
      /**
       * Sets up the listener for parent resizes
       */
      protected function onAdd(e:FlexEvent):void {
        
        this.parent.addEventListener(Event.RESIZE, this.onParentResize);
      }
      
      /**
       * Ensures playback is stopped and removes the listener for parent resizes
       */
      protected function onRemove(e:FlexEvent):void {
        
        this.source = null;

        this.parent.removeEventListener(Event.RESIZE, this.onParentResize);
      }
      
      /**
       * Forces layout recalculation upon parent resize
       */
      protected function onParentResize(e:Event):void {
        
        // Re-setting these values forces resizing, manually calling
        // any of the invalidate*() or validate*() methods does not work
        this.percentWidth = this.percentHeight = 100;
      }

    ]]>
  </fx:Script>
  
</s:VideoPlayer>