Actionscript 3 Air应用程序在DVD中运行
我创建了Air应用程序,并将其发布为嵌入运行时的应用程序,其配置文件是ExtendedDesktop。使用FlashProfessionalCC。它由菜单、测验和mp4视频组成。视频通过Netconnection加载。如果我在我的电脑上运行应用程序,一切都正常,但是,如果我将文件刻录到DVD或复制到拇指驱动器,视频或视频播放器控件将根本不显示。应用程序的其余部分在DVD和拇指驱动器(菜单、测验、打开外部PDF文件等)中运行良好,只是视频没有显示Actionscript 3 Air应用程序在DVD中运行,actionscript-3,Actionscript 3,我创建了Air应用程序,并将其发布为嵌入运行时的应用程序,其配置文件是ExtendedDesktop。使用FlashProfessionalCC。它由菜单、测验和mp4视频组成。视频通过Netconnection加载。如果我在我的电脑上运行应用程序,一切都正常,但是,如果我将文件刻录到DVD或复制到拇指驱动器,视频或视频播放器控件将根本不显示。应用程序的其余部分在DVD和拇指驱动器(菜单、测验、打开外部PDF文件等)中运行良好,只是视频没有显示 // ######################
// ###############################
// ############# CONSTANTS
// ###############################
// time to buffer for the video in sec.
const BUFFER_TIME:Number = 8;
// start volume when initializing player
const DEFAULT_VOLUME:Number = 0.6;
// update delay in milliseconds.
const DISPLAY_TIMER_UPDATE_DELAY:int = 10;
// smoothing for video. may slow down old computers
const SMOOTHING:Boolean = true;
// ###############################
// ############# VARIABLES
// ###############################
// flag for knowing if user hovers over description label
var bolDescriptionHover:Boolean = false;
// flag for knowing in which direction the description label is currently moving
var bolDescriptionHoverForward:Boolean = true;
// flag for knowing if flv has been loaded
var bolLoaded:Boolean = false;
// flag for volume scrubbing
var bolVolumeScrub:Boolean = false;
// flag for progress scrubbing
var bolProgressScrub:Boolean = false;
// holds the number of the active video
var intActiveVid:int;
// holds the last used volume, but never 0
var intLastVolume:Number = DEFAULT_VOLUME;
// net connection object for net stream
var ncConnection:NetConnection;
// net stream object
var nsStream:NetStream;
// object holds all meta data
var objInfo:Object;
// shared object holding the player settings (currently only the volume)
var shoVideoPlayerSettings:SharedObject = SharedObject.getLocal("playerSettings");
// url to flv file
var strSource:String = root.loaderInfo.parameters.playlist == null ? "video/playlist.xml" : root.loaderInfo.parameters.playlist;
// timer for updating player (progress, volume...)
var tmrDisplay:Timer;
// loads the xml file
var urlLoader:URLLoader;
// holds the request for the loader
var urlRequest:URLRequest;
// playlist xml
var xmlPlaylist:XML;
// ###############################
// ############# FUNCTIONS
// ###############################
// sets up the player
function initVideoPlayer():void {
// hide video controls on initialisation
mcVideoControls.visible = false;
// hide buttons
//mcVideoControls.btnUnmute.visible = false;
//mcVideoControls.btnPause.visible = false;
mcVideoControls.btnFullscreenOff.visible = false;
// set the progress/preload fill width to 1
mcVideoControls.mcProgressFill.mcFillRed.width = 1;
mcVideoControls.mcProgressFill.mcFillGrey.width = 1;
// set time and duration label
mcVideoControls.lblTimeDuration.htmlText = "<font color='#ffffff'>00:00</font> / 00:00";
// add global event listener when mouse is released
stage.addEventListener(MouseEvent.MOUSE_UP, mouseReleased, false, 0, true);
// add fullscreen listener
stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullscreen, false, 0, true);
// add event listeners to all buttons
mcVideoControls.btnPause.addEventListener(MouseEvent.CLICK, pauseClicked, false, 0, true);
mcVideoControls.btnPlay.addEventListener(MouseEvent.CLICK, playClicked, false, 0, true);
mcVideoControls.btnFullscreenOn.addEventListener(MouseEvent.CLICK, fullscreenOnClicked, false, 0, true);
mcVideoControls.btnFullscreenOff.addEventListener(MouseEvent.CLICK, fullscreenOffClicked, false, 0, true);
mcVideoControls.btnProgressBar.addEventListener(MouseEvent.MOUSE_DOWN, progressScrubberClicked, false, 0, true);
mcVideoControls.mcProgressScrubber.btnProgressScrubber.addEventListener(MouseEvent.MOUSE_DOWN, progressScrubberClicked, false, 0, true);
// create timer for updating all visual parts of player and add
// event listener
tmrDisplay = new Timer(DISPLAY_TIMER_UPDATE_DELAY);
tmrDisplay.addEventListener(TimerEvent.TIMER, updateDisplay, false, 0, true);
// create a new net connection, add event listener and connect
// to null because we don't have a media server
ncConnection = new NetConnection();
ncConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler, false, 0, true);
ncConnection.connect(null);
// create a new netstream with the net connection, add event
// listener, set client to this for handling meta data and
// set the buffer time to the value from the constant
nsStream = new NetStream(ncConnection);
nsStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler, false, 0, true);
nsStream.client = this;
nsStream.bufferTime = BUFFER_TIME;
// attach net stream to video object on the stage
vidDisplay.attachNetStream(nsStream);
// set the smoothing value from the constant
vidDisplay.smoothing = SMOOTHING;
// set default volume and get volume from shared object if available
var tmpVolume:Number = DEFAULT_VOLUME;
if(shoVideoPlayerSettings.data.playerVolume != undefined) {
tmpVolume = shoVideoPlayerSettings.data.playerVolume;
intLastVolume = tmpVolume;
}
// create new request for loading the playlist xml, add an event listener
// and load it
urlRequest = new URLRequest(strSource);
urlLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, playlistLoaded, false, 0, true);
urlLoader.load(urlRequest);
nsStream.play(strSource);
}
function playClicked(e:MouseEvent):void {
// check's, if the flv has already begun
// to download. if so, resume playback, else
// load the file
if(!bolLoaded) {
nsStream.play(strSource);
bolLoaded = true;
}
else{
nsStream.resume();
}
vidDisplay.visible = true;
// switch play/pause visibility
mcVideoControls.btnPause.visible = true;
mcVideoControls.btnPlay.visible = false;
}
function pauseClicked(e:MouseEvent):void {
// pause video
nsStream.pause();
// switch play/pause visibility
mcVideoControls.btnPause.visible = false;
mcVideoControls.btnPlay.visible = true;
}
function progressScrubberClicked(e:MouseEvent):void {
// set progress scrub flag to true
bolProgressScrub = true;
// start drag
mcVideoControls.mcProgressScrubber.startDrag(true, new Rectangle(0, 3.7, 432, 0)); // NOW TRUE
}
function mouseReleased(e:MouseEvent):void {
// set progress/volume scrub to false
bolVolumeScrub = false;
bolProgressScrub = false;
// stop all dragging actions
mcVideoControls.mcProgressScrubber.stopDrag();
// update progress/volume fill
mcVideoControls.mcProgressFill.mcFillRed.width = mcVideoControls.mcProgressScrubber.x + 5;
}
function updateDisplay(e:TimerEvent):void {
// checks, if user is scrubbing. if so, seek in the video
// if not, just update the position of the scrubber according
// to the current time
if(bolProgressScrub)
nsStream.seek(Math.round(mcVideoControls.mcProgressScrubber.x * objInfo.duration / 432))
else
mcVideoControls.mcProgressScrubber.x = nsStream.time * 432 / objInfo.duration;
// set time and duration label
mcVideoControls.lblTimeDuration.htmlText = "<font color='#ffffff'>" + formatTime(nsStream.time) + "</font> / " + formatTime(objInfo.duration);
// update the width from the progress bar. the grey one displays
// the loading progress
mcVideoControls.mcProgressFill.mcFillRed.width = mcVideoControls.mcProgressScrubber.x + 5;
mcVideoControls.mcProgressFill.mcFillGrey.width = nsStream.bytesLoaded * 438 / nsStream.bytesTotal;
// update volume and the red fill width when user is scrubbing
if(bolVolumeScrub) {
setVolume((mcVideoControls.mcVolumeScrubber.x - 318) / 53);
mcVideoControls.mcVolumeFill.mcFillRed.width = mcVideoControls.mcVolumeScrubber.x - 371 + 53;
}
// chech if user is currently hovering over description label
if(bolDescriptionHover) {
// check in which direction we're currently moving
if(bolDescriptionHoverForward) {
// move to the left and check if we've shown everthing
mcVideoControls.mcVideoDescription.lblDescription.x -= 0.1;
if(mcVideoControls.mcVideoDescription.lblDescription.textWidth - 133 <= Math.abs(mcVideoControls.mcVideoDescription.lblDescription.x))
bolDescriptionHoverForward = false;
} else {
// move to the right and check if we're back to normal
mcVideoControls.mcVideoDescription.lblDescription.x += 0.1;
if(mcVideoControls.mcVideoDescription.lblDescription.x >= 0)
bolDescriptionHoverForward = true;
}
} else {
// reset label position and direction variable
mcVideoControls.mcVideoDescription.lblDescription.x = 0;
bolDescriptionHoverForward = true;
}
}
function onMetaData(info:Object):void {
// stores meta data in a object
objInfo = info;
// now we can start the timer because
// we have all the neccesary data
if(!tmrDisplay.running)
tmrDisplay.start();
}
function netStatusHandler(event:NetStatusEvent):void {
// handles net status events
switch (event.info.code) {
// trace a messeage when the stream is not found
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + strSource);
break;
// when the video reaches its end, we check if there are
// more video left or stop the player
case "NetStream.Play.Stop":
//if(intActiveVid + 1 < xmlPlaylist..vid.length())
//playNext();
//else
nsStream.close();
removeChild(vidDisplay);
removeChild(mcVideoControls);
MovieClip(root).gotoAndPlay(2701);
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.displayState = StageDisplayState.NORMAL;
break;
}
}
function setVolume(intVolume:Number = 0):void {
// create soundtransform object with the volume from
// the parameter
var sndTransform = new SoundTransform(intVolume);
// assign object to netstream sound transform object
nsStream.soundTransform = sndTransform;
// hides/shows mute and unmute button according to the
// volume
if(intVolume > 0) {
mcVideoControls.btnMute.visible = true;
mcVideoControls.btnUnmute.visible = false;
} else {
mcVideoControls.btnMute.visible = false;
mcVideoControls.btnUnmute.visible = true;
}
// store the volume in the flash cookie
shoVideoPlayerSettings.data.playerVolume = intVolume;
shoVideoPlayerSettings.flush();
}
function formatTime(t:int):String {
// returns the minutes and seconds with leading zeros
// for example: 70 returns 01:10
var s:int = Math.round(t);
var m:int = 0;
if (s > 0) {
while (s > 59) {
m++; s -= 60;
}
return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
} else {
return "00:00";
}
}
function fullscreenOnClicked(e:MouseEvent):void {
// go to fullscreen mode
stage.displayState = StageDisplayState.FULL_SCREEN;
}
function fullscreenOffClicked(e:MouseEvent):void {
// go to back to normal mode
stage.displayState = StageDisplayState.NORMAL;
}
function onFullscreen(e:FullScreenEvent):void {
// check if we're entering or leaving fullscreen mode
if (e.fullScreen) {
// switch fullscreen buttons
mcVideoControls.btnFullscreenOn.visible = false;
mcVideoControls.btnFullscreenOff.visible = true;
// size up video display
MovieClip(root).PlayerFrame.height = stage.height;
MovieClip(root).PlayerFrame.width = stage.width;
MovieClip(root).PlayerFrame.x = 0;
MovieClip(root).PlayerFrame.y = 0;
// bottom center align controls
} else {
// switch fullscreen buttons
mcVideoControls.btnFullscreenOn.visible = true;
mcVideoControls.btnFullscreenOff.visible = false;
MovieClip(root).PlayerFrame.x = 603;
MovieClip(root).PlayerFrame.y = 204;
MovieClip(root).PlayerFrame.width = 1020;
MovieClip(root).PlayerFrame.height = 614;
}
}
function playlistLoaded(e:Event):void {
// create new xml with loaded data from loader
xmlPlaylist = new XML(urlLoader.data);
// set source of the first video but don't play it
playVid(0, true)
// show controls
mcVideoControls.visible = true;
}
function playVid(intVid:int = 0, bolPlay = true):void {
if(bolPlay) {
// stop timer
tmrDisplay.stop();
// play requested video
nsStream.play(String(xmlPlaylist..vid[intVid].@src));
// switch button visibility
mcVideoControls.btnPause.visible = true;
mcVideoControls.btnPlay.visible = false;
} else {
strSource = xmlPlaylist..vid[intVid].@src;
}
// show video display
vidDisplay.visible = true;
// reset description label position and assign new description
mcVideoControls.mcVideoDescription.lblDescription.x = 0;
mcVideoControls.mcVideoDescription.lblDescription.htmlText = "<font color='#ffffff'>" + String(xmlPlaylist..vid[intVid].@desc) + "</font>";
// update active video number
intActiveVid = intVid;
}
// ###############################
// ############# INIT PLAYER
// ###############################
initVideoPlayer();
//###############################
//常数
// ###############################
//视频缓冲时间(秒)。
常量缓冲时间:数字=8;
//初始化播放机时启动卷
const DEFAULT_VOLUME:Number=0.6;
//以毫秒为单位的更新延迟。
常数显示\定时器\更新\延迟:int=10;
//视频平滑。可能会减慢旧电脑的速度
常量平滑:布尔=真;
// ###############################
//变量
// ###############################
//用于知道用户是否悬停在描述标签上的标志
var boldDescriptionHover:Boolean=false;
//用于了解描述标签当前移动方向的标志
var bolddescriptionhoverforward:Boolean=true;
//用于了解flv是否已加载的标志
布尔值=false;
//卷清理的标志
变量bolVolumeScrub:Boolean=false;
//清除进度标志
var:Boolean=false;
//保存活动视频的编号
var intActiveVid:int;
//保存最后使用的卷,但从不为0
var intLastVolume:Number=默认卷;
//网络流的网络连接对象
网络连接:网络连接;
//网络流对象
nsStream:NetStream;
//对象保存所有元数据
var objInfo:对象;
//保存播放机设置的共享对象(当前仅音量)
var shoVideoPlayerSettings:SharedObject=SharedObject.getLocal(“playerSettings”);
//flv文件的url
var strSource:String=root.loaderInfo.parameters.playlist==null?“video/playlist.xml”:root.loaderInfo.parameters.playlist;
//更新播放机的计时器(进度、音量…)
var-tmrDisplay:定时器;
//加载xml文件
var-urlLoader:urlLoader;
//保存对加载程序的请求
var-urlRequest:urlRequest;
//播放列表xml
var-xmlPlaylist:XML;
// ###############################
//功能
// ###############################
//设置播放器
函数initVideoPlayer():void{
//在初始化时隐藏视频控件
mcVideoControls.visible=false;
//隐藏按钮
//mcVideoControls.btnUnmute.visible=false;
//mcVideoControls.btnPause.visible=false;
mcVideoControls.btnFullscreenOff.visible=false;
//将进度/预加载填充宽度设置为1
mcVideoControls.mcProgressFill.mcFillRed.width=1;
mcVideoControls.mcProgressFill.mcFillGrey.width=1;
//设置时间和持续时间标签
mcVideoControls.lblTimeDuration.htmlText=“00:00/00:00”;
//释放鼠标时添加全局事件侦听器
stage.addEventListener(MouseEvent.MOUSE\u UP,mouseereleased,false,0,true);
//添加全屏侦听器
stage.addEventListener(FullScreenEvent.FULL_SCREEN,On FullScreen,false,0,true);
//将事件侦听器添加到所有按钮
mcVideoControls.btnPause.addEventListener(MouseEvent.CLICK,pauseClicked,false,0,true);
mcVideoControls.btnPlay.addEventListener(MouseEvent.CLICK,playClicked,false,0,true);
mcVideoControls.btnFullscreenOn.addEventListener(MouseEvent.CLICK,fullscreenOnClicked,false,0,true);
mcVideoControls.btnFullscreenOff.addEventListener(MouseEvent.CLICK,fullscreenOffClicked,false,0,true);
mcVideoControls.btnProgressBar.addEventListener(MouseEvent.MOUSE_向下,ProgressScriberClicked,false,0,true);
mcVideoControls.mcprogressscriber.btnprogressscriber.addEventListener(MouseEvent.MOUSE_向下,ProgressScriberClicked,false,0,true);
//创建计时器以更新播放器的所有可视部分并添加
//事件侦听器
tmrDisplay=新定时器(显示定时器更新延时);
tmrDisplay.addEventListener(TimerEvent.TIMER,updateDisplay,false,0,true);
//创建新的网络连接,添加事件侦听器并连接
//设置为null,因为我们没有媒体服务器
ncConnection=新的NetConnection();
ncConnection.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler,false,0,true);
ncConnection.connect(空);
//使用网络连接创建新的netstream,添加事件
//侦听器,将客户端设置为该值以处理元数据和
//将缓冲时间设置为常量中的值
nsStream=新的NetStream(ncConnection);
nsStream.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler,false,0,true);
nsStream.client=这个;
nsStream.bufferTime=缓冲区时间;
//将网络流附加到舞台上的视频对象
vidDisplay.attachNetStream(nsStream);
//从常量设置平滑值
vidDisplay.smoothing=平滑;
//设置默认卷并从共享对象获取卷(如果可用)
var tmpVolume:Number=默认卷;
if(shoVideoPlayerSettings.data.playerVolume!=未定义){
tmpVolume=shoVideoPlayerSettings.data.playerVolume;
intLastVolume=tmpVolume;
}
//创建加载播放列表xml的新请求,添加事件侦听器
//然后加载它
urlRequest=新的urlRequest(strSource);
urlLoader=新的urlLoader();
urlLoader.addEventListener(Event.COMPLETE,playloadded,false,0,true);
加载(urlRequest);
nsStream.play(strSource);
}
函数playClicked(e:MouseeEvent):无效{
//检查,如果flv已经开始
//下载。如果是,请继续播放,否则
//加载文件
如果(!已加载){
<?xml version="1.0" encoding="UTF-8"?>
<videolist>
<vid src="video/Intro.mp4" desc="Intro"/>
</videolist>