Avg. Rating 3.5

Problem

By default JW Player Version does not support embedding into Flex application (http://developer.longtailvideo.com/trac/wiki/FlexEmbedding).

Solution

You just need to overlap original RootReference class with your own, when loading player in to your Flex application. You don't need to get JW Player source code from SVN and fix it to apply this solution, but this is one of the approach.

Detailed explanation

This is a workaroud to made Longtail FLV Player 5

(http://www.longtailvideo.com/players/jw-flv-player/), work within Adobe Flex.
 
This class is overlaps original class:
 com.longtailvideo.jwplayer.utils.RootReference compiled in Player.
 
WARNING:
 This class MUST be placed strictly in: com.longtailvideo.jwplayer.utils class path.
 
Usage example:
 
        <?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:com="com.*"
    layout="vertical" verticalAlign="middle" horizontalAlign="center"
    creationComplete="handleCreationComplete()">
    
  <mx:Script>
    <![CDATA[
      import com.longtailvideo.jwplayer.utils.RootReference;
      import mx.core.UIComponent;
      import mx.events.FlexEvent;

      private var _loader:Loader;
      private var _playerObject:DisplayObject;
      private var _flashVars:String;
      private var _autoStart:Boolean = true;
      private var _playerURL:String = "player.swf";

      private var _videoURL:String = "someVideo.flv";
      private var _uic:UIComponent;
      private var _jwPlayerHack:RootReference;

      protected function handleCreationComplete():void {
        // You can add Player container not only in some UIComponent but also on stage.
        _uic = UIComponent(canv.addChild (new UIComponent ()));

        _uic.width = 400;
        _uic.height = 300;

        _jwPlayerHack = new RootReference(_uic);
        
        videoSource = _videoURL;
      }

      public function set videoSource(url:String):void {
        if (!url) url = "";
        // Here you can set any FlashVars supported by player.
        // see http://developer.longtailvideo.com/trac/wiki/Player5FlashVars.
        _flashVars = "file=" + url + "&autostart=true";
        _flashVars += "&t=" + getTimer().toString();

        _loader = new Loader();
        _loader.contentLoaderInfo.addEventListener(Event.INIT, onLoadInit);

        var ldrContext:LoaderContext = new LoaderContext(false,
            ApplicationDomain.currentDomain);
        var request:URLRequest = new URLRequest(_playerURL);
        var urlVars:URLVariables = new URLVariables();
       
        urlVars.decode(_flashVars);
        request.data = urlVars;
       
        _loader.load(request, ldrContext);
      }
     
      private function onLoadInit(event:Event):void {   
        _playerObject = _loader.content as DisplayObject;
        _playerObject.addEventListener("jwplayerReady", onPlayerReady);
       
        RootReference.root = _playerObject.root;
        _uic.addChild(_loader);
      }

      private function onPlayerReady(event:*=null):void {
        _jwPlayerHack.fixMaskIssue();
      }
    ]]>
  </mx:Script>   
  
  <mx:Canvas id="canv" width="400" height="300" backgroundColor="0xffffff" />
</mx:Application>
 
  
src.zip
[RootReference class overlap source]

+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes