Air App在DVD中运行

时间:2015-03-26 02:54:28

标签: actionscript-3

我创建了Air App并将其作为Application with Run-time Embedded发布,它的配置文件是Extended Desktop。使用Flash Professional CC。它包括菜单,测验和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();

并且xml文件包含:

<?xml version="1.0" encoding="UTF-8"?>
<videolist>
    <vid src="video/Intro.mp4" desc="Intro"/>
</videolist>

请帮忙。

0 个答案:

没有答案