flex加载jwplayer的解决办法

2024-01-01 19:08

本文主要是介绍flex加载jwplayer的解决办法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

今天偶尔看到了这篇文章,转载一下,以备所需。之前尝试过在flex工程中加入jwplayer,以失败告终。以下转载的方法还没有亲身试验。

原文地址如下:

http://cookbooks.adobe.com/post_Embedding_JW_Player_Version_5_into_Flex-16707.html

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>
 
  

RootReference.as:(也就是原文src.zip中的内容)


package com.longtailvideo.jwplayer.utils

{

import flash.debugger.enterDebugger;

import flash.display.DisplayObject;

import flash.display.DisplayObjectContainer;

import flash.display.MovieClip;

import flash.display.Stage;

import flash.display.StageDisplayState;

import flash.events.Event;

import flash.events.EventDispatcher;

import flash.events.FullScreenEvent;

import flash.geom.Point;

import flash.geom.Rectangle;

import flash.media.Video;

import flash.system.Capabilities;

import flash.system.Security;

import mx.core.Application;

import mx.core.UIComponent;

/**

* 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>

*

* @author Dmitry 'Reijii' Kochetov, Marat '7thsky' Atayev

* @version Jan 14, 2010

* @skype kodjii

*

* This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

* @see http://creativecommons.org/licenses/by-sa/3.0/

*/

public class RootReferenceextends EventDispatcher

{

public static var root : DisplayObject;

public static var stage : RootReference;

public static var container : UIComponent;

public static var instance : RootReference;

public static var _stageInstance : Stage;

public static var _playerUI : MovieClip;

public function RootReference ( $displayObj : DisplayObject ) : void

{

if ( ! RootReference.instance )

{

RootReference.instance= this;

RootReference.container = $displayObjas UIComponent;

RootReference.stage= RootReference.instance;

try

{

Security.allowDomain("*" );

}

catch ( e : Error )

{

// This may not work in the AIR testing suite

}

if ( container.stage )

{

_stageInstance = container.stage;

_stageInstance.addEventListener( Event.ADDED, handleAdded );

}

else

{

container.addEventListener( Event.ADDED_TO_STAGE, handleAddedToStage,false, 0, true );

}

}

}

private function handleAddedToStage ( event:Event ) : void

{

container.removeEventListener( Event.ADDED_TO_STAGE, handleAddedToStage );

_stageInstance = container.stage;

_stageInstance.addEventListener( Event.ADDED, handleAdded );

}

private function handleAdded ( event:Event ) : void

{

if ( event.targetis Video )

{

enterDebugger();

}

}

public function fixMaskIssue () : void

{

var i: int;

var parent: MovieClip; 

var child: DisplayObject;

var mask: DisplayObject;

var tl: Point; 

var br: Point;

if ( ( parent = _playerUI ) !=null )

{

for ( i = 0; i < parent.numChildren; i++ )

{

if ( parent.getChildAt( i ).mask)

{

mask = parent.getChildAt( i ).mask;

break;

}

}

}

if ( mask )

{

tl = container.localToGlobal(new Point( 0, 0 ) );

br = container.localToGlobal(new Point( container.width, container.height ) );

mask.x = tl.x;

mask.y = tl.y;

mask.width = br.x - tl.x;

mask.height = br.y - tl.y;

}

}

// STAGE EMULATION ;)

public var stage : Object = {};

public function get stageWidth () : int

{

return container.width;

}

public function get stageHeight () : int

{

return container.height;

}

override public function addEventListener ( type:String, listener:Function, useCapture:Boolean =false, priority:int = 0, useWeakReference:Boolean = false ) : void

{

_stageInstance.addEventListener( type, listener, useCapture, priority, useWeakReference );

}

override public function removeEventListener ( type:String, listener:Function, useCapture:Boolean =false ) : void

{

_stageInstance.removeEventListener( type, listener, useCapture );

}

override public function hasEventListener ( type:String ) : Boolean

{

return _stageInstance.hasEventListener( type );

}

override public function willTrigger ( type:String ) : Boolean

{

return _stageInstance.willTrigger( type );

}

override public function dispatchEvent ( event:Event ) : Boolean

{

return _stageInstance.dispatchEvent( event );

}

public function addChildAt ( $child:DisplayObject, $index:int ) : DisplayObject

{

if ( $childis MovieClip )

{

_playerUI = MovieClip( $child );

}

return container.addChildAt( $child, $index );

}

public function addChild ( $child:DisplayObject ) : DisplayObject

{

return addChildAt( $child, container.numChildren ); 

}

public function removeChild ( $child:DisplayObject ) : DisplayObject

{

return container.removeChild( $child );

}

public function get numChildren () : uint

{

return container.numChildren;

}

public function get displayState () : String

{

return _stageInstance ? _stageInstance.displayState :'';

}

private var _savedParent : DisplayObjectContainer;

private var _savedLayout : String;

private var _savedWidth : Number;

private var _savedHeight : Number;

private var _savedX : Number;

private var _savedY : Number;

private var _savedIndex : Number;

private var _isLocked : Boolean = false;

public function set displayState ( $value:String ) : void

{

if ( $value == StageDisplayState.FULL_SCREEN )

{

_isLocked = false;

setFullScreen();

}

elseif ( _stageInstance.displayState == StageDisplayState.FULL_SCREEN )

{

_isLocked = true;

setNormalScreen();

}

}

private function handleFullScreen ( event:FullScreenEvent ) : void

{

if ( event.fullScreen ==false && _isLocked == false  )

{

setNormalScreen();

}

}

private function setFullScreen () : void

{

_savedWidth = container.width;

_savedHeight = container.height;

_savedLayout    = Application.application.layout;

_savedParent = container.parent;

Application.application.layout ="absolute";

_savedIndex = _savedParent.getChildIndex( container );

Application.application.addChild( _savedParent.removeChild( container ) );

_savedX = container.x;

_savedY = container.y;

container.x = 0;

container.y = 0;

_stageInstance.addEventListener( FullScreenEvent.FULL_SCREEN, handleFullScreen );

_stageInstance.fullScreenSourceRect =new Rectangle( 0, 0, Capabilities.screenResolutionX, Capabilities.screenResolutionY );

_stageInstance.displayState = StageDisplayState.FULL_SCREEN;

container.width = Capabilities.screenResolutionX;

container.height = Capabilities.screenResolutionY;

Object( RootReference.root ).redraw();

fixMaskIssue();

}

private function setNormalScreen () : void

{

_stageInstance.displayState = StageDisplayState.NORMAL;

Application.application.layout = _savedLayout;

_savedParent.addChildAt( Application.application.removeChild( container ),_savedIndex );

container.width = _savedWidth;

container.height = _savedHeight;

container.x = _savedX;

container.y = _savedY;

Object( RootReference.root ).redraw();

fixMaskIssue();

_stageInstance.removeEventListener( FullScreenEvent.FULL_SCREEN, handleFullScreen );

}

public function get scaleMode () : String

{

return _stageInstance ? _stageInstance.scaleMode :'';

}

public function set scaleMode ( $value:String ) : void

{

_stageInstance.scaleMode = $value;

}

}

}


这篇关于flex加载jwplayer的解决办法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/560217

相关文章

springboot加载不到nacos配置中心的配置问题处理

《springboot加载不到nacos配置中心的配置问题处理》:本文主要介绍springboot加载不到nacos配置中心的配置问题处理,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录springboot加载不到nacos配置中心的配置两种可能Spring Boot 版本Nacos

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

IDEA下"File is read-only"可能原因分析及"找不到或无法加载主类"的问题

《IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题》:本文主要介绍IDEA下Fileisread-only可能原因分析及找不到或无法加载主类的问题,具有很好的参... 目录1.File is read-only”可能原因2.“找不到或无法加载主类”问题的解决总结1.File

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示

在 PyQt 加载 UI 三种常见方法

《在PyQt加载UI三种常见方法》在PyQt中,加载UI文件通常指的是使用QtDesigner设计的.ui文件,并将其转换为Python代码,以便在PyQt应用程序中使用,这篇文章给大家介绍在... 目录方法一:使用 uic 模块动态加载 (不推荐用于大型项目)方法二:将 UI 文件编译为 python 模

vscode不能打开终端问题的解决办法

《vscode不能打开终端问题的解决办法》:本文主要介绍vscode不能打开终端问题的解决办法,问题的根源是Windows的安全软件限制了PowerShell的运行,而VSCode默认使用Powe... 遇到vscode不能打开终端问题,一直以为是安全软件限制问题,也没搜到解决方案,因为影响也不大,就没有管

Spring框架中@Lazy延迟加载原理和使用详解

《Spring框架中@Lazy延迟加载原理和使用详解》:本文主要介绍Spring框架中@Lazy延迟加载原理和使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录一、@Lazy延迟加载原理1.延迟加载原理1.1 @Lazy三种配置方法1.2 @Component

SpringBoot中配置文件的加载顺序解读

《SpringBoot中配置文件的加载顺序解读》:本文主要介绍SpringBoot中配置文件的加载顺序,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录SpringBoot配置文件的加载顺序1、命令⾏参数2、Java系统属性3、操作系统环境变量5、项目【外部】的ap

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

Python运行中频繁出现Restart提示的解决办法

《Python运行中频繁出现Restart提示的解决办法》在编程的世界里,遇到各种奇怪的问题是家常便饭,但是,当你的Python程序在运行过程中频繁出现“Restart”提示时,这可能不仅仅是令人头疼... 目录问题描述代码示例无限循环递归调用内存泄漏解决方案1. 检查代码逻辑无限循环递归调用内存泄漏2.