FLV播放器是一种专用于播放FLV格式视频的播放器,FLV是时下最流行的播放格式,其特点是压缩比高、文件容量小、支持渐进式缓冲播放等。Flex4.0中的VideoDisplay组件专用于播放Flv格式视频。
一、前期准备
1.组织文件结构:
图1(FLV播放器文件的组织结构)
2.导入Cairngorm框架
二、使用FlvModel类存储数据、状态及资源
FlvModel类继承与Cairngorm框架的ModelLocator,用以存储数据状态和资源,例如,当前播放的视频地址、是否为全频状态、图片资源等都存储于FlvModel类中。以下代码定义了FlvModel类。
- package com.xi.flvPlayer.model
- {
- import com.adobe.cairngorm.model.ModelLocator;
- import mx.controls.ToolTip;
-
- public class FlvModel implements ModelLocator
- {
- private static var flvModel:FlvModel=new FlvModel(); //定义FlvModel类实例flvModel
-
- public static function getInstance():FlvModel{ //获得FlvModel类的实例
- return flvModel;
- }
-
- public static var currVideo:String=""; //当前视频播放地址
- public static var videoSource:String=""; //将要加载的视频地址
- public static var isFullScreen:Boolean=false; //是否全屏状态
-
- /*---------------------------------图标资源----------------------------------*/
- [Bindable]
- [Embed(source="/assets/images/btn_moveover_break.png")]
- public var btn_moveover_break:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_moveover_fullscreen.png")]
- public var btn_moveover_fullscreen:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_moveover_play.png")]
- public var btn_moveover_play:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_moveover_stop.png")]
- public var btn_moveover_stop:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_normal_break.png")]
- public var btn_normal_break:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_normal_fullscreen.png")]
- public var btn_normal_fullscreen:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_normal_play.png")]
- public var btn_normal_play:Class;
-
- [Bindable]
- [Embed(source="/assets/images/btn_normal_stop.png")]
- public var btn_normal_stop:Class;
-
- [Bindable]
- [Embed(source="/assets/images/ico_break.png")]
- public var ico_break:Class;
- }
- }
static关键字表示静态变量。静态变量可直接存取,其他变量需要实例化后才能存取。以下代码存取FlvModel
类中的变量currVideo和btn_normal_play.
import com.xi.flvPlayer.model.*;
FlvModel.currVideo="34324";
t=FlvModel.getInstance().btn_normal_play;
三、使用FlvControl类监听事件
FlvControl类继承与Cairngorm框架的FrontControl类,用于监听CairngormEvent事件。习惯上,CairngormEvent事件的标识符字符串也都存储于前台控制器中。
以下代码定义了FlvControl类:
- package com.xi.flvPlayer.control
- {
- import com.adobe.cairngorm.control.FrontController;
- import com.xi.flvPlayer.commands.*;
- public class FlvControl extends com.adobe.cairngorm.control.FrontController
- {
- public function FlvControl():void //构造函数
- {
- initialiseCommands();
- }
-
- public function initialiseCommands():void{
- addCommand(FlvControl.EVENT_OPEN_VIDEO,OpenVideoCommand);
- }
-
- public static var EVENT_OPEN_VIDEO:String="openVideo"; //定义openVideo标识
- }
- }
未完待续。。。
项目源码:
阅读(1023) | 评论(0) | 转发(0) |