helihongzhizhuo
nickname_oo
采纳率0%
2015-06-24 01:57 阅读 1.7k

flex videodisplay totalTime总是获取不到呢

5

使用的flex as3.0 ,用videodisplay组件,totalTime总是获取不到呢,求大神指教

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • helihongzhizhuo nickname_oo 2015-06-24 04:41

    <?xml version="1.0" encoding="utf-8"?>
    layout="vertical"
    creationComplete="playinit()" title="视频播放"
    width="960"
    height="600"
    showCloseButton="true"
    close="closeWindow()" doubleClickEnabled="true" doubleClick="display();">
    mx:Script
    <![CDATA[
    import mx.events.StateChangeEvent;
    import mx.collections.ArrayCollection;
    import mx.events.SliderEvent;
    import mx.events.VideoEvent;
    import flash.display.Stage;
    import mx.core.Application;
    import mx.managers.PopUpManager;
    import mx.core.Application;
    import flash.events.FullScreenEvent;
    import mx.controls.Alert;

            private var isplaying:Boolean = true;//默認為播放狀態       
            public var playPosition:Number;//播放進度      
            private var soundPosition:Number;//聲音大小
    
            [Bindable]
                public var rdpPlayAddr:String;
            private var video_totalTime:Number = 0;
        //播放地址
     //     public var url:String="";
     //     private var playUrl:String="http://www.xbqing.com/video/";
        private function closeWindow():void
        {
            try {
                flv_video.stop();
                flv_video.close();
            } catch(err:Error) {
                err.getStackTrace();
            }
            PopUpManager.removePopUp(this);
        }
    
        private var titleWindowWidth:Number=0;
        private var titleWindowHeight:Number=0;
        private var tolTime:Number = 0;
    

    // private var cmeTimer:Timer = new Timer(100, 10);
    internal function initTime(evt:Event):void
    {
    while(tolTime <= 0) {
    tolTime = Math.round(flv_video.totalTime);
    if (tolTime > 0) {
    Alert.show("tolTime:" +tolTime);
    flv_video.totalTime = tolTime;
    break;
    }
    }

       }
        private function playinit():void
        {
    

    // dispatchEvent(new Event("totalTimeUpdated"));
    // dispatchEvent(new Event("metadataReceived"));
    titleWindowWidth = this.width;
    titleWindowHeight = this.height;

    // flv_video.source = "rdppaly/Administrator_192.168.1.38_rdp_20110815150314.flv";
    // setTotalTime();
    // flv_video.addEventListener(VideoEvent.COMPLETE, initTime);
    flv_video.source = rdpPlayAddr;
    hs.enabled=true;
    if (isNaN(flv_video.totalTime) || flv_video.totalTime <= 0 ) {
    flv_video.play();
    flv_video.totalTime = 600;
    }
    hs.maximum = flv_video.totalTime;
    if (playPosition > 0) {
    hs.value=playPosition;
    flv_video.playheadTime = playPosition;
    flv_video.play();
    // Alert.show("dage:" +flv_video.playheadTime);
    // isplaying = true;
    play_btn.label="暂停";
    stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullScreenEvent);

            } else {
    

    // flv_video.source = rdpPlayAddr;
    // hs.enabled = true;
    // hs.maximum = flv_video.totalTime;
    stage.addEventListener(FullScreenEvent.FULL_SCREEN,fullScreenEvent);
    }

            //监听全屏事件
    
        }
        //处理全屏事件,设置弹出窗和VideoDisplay大小
        private function fullScreenEvent(event:FullScreenEvent):void
        {
            try
            {
                if(this.stage.displayState == StageDisplayState.FULL_SCREEN)
                {//全屏
                    this.x=0;
                    this.y=0;
                    this.width=Application.application.width;
                    this.height=Application.application.height;
                    flv_video.width=Application.application.width-50;
                    flv_video.height=Application.application.height-110;
                    fs.selected=true;
    
    
                }
                else
                {
                    fs.selected=false;
                    this.width=titleWindowWidth;
                    this.height=titleWindowHeight;
                    //VideoDisplay恢复大小
                    flv_video.width=800;
                    flv_video.height=600;
                    PopUpManager.centerPopUp(this);
                }
            }
            catch(e:*)
            {
    
            }
        }
        //設罷播放源
        private function flvplay(event:Event):void
        {
        //  playUrl=playUrl+url;
    

    // flv_video.source = "rdppaly/Administrator_192.168.1.38_rdp_20110815150314.flv";
    flv_video.source = rdpPlayAddr;
    hs.enabled=true;
    if(isplaying)
    {
    if(flv_video.playing)
    {
    flv_video.pause();
    }
    play_btn.label="播放"
    }
    else
    {
    flv_video.play();
    play_btn.label="暂停"
    }
    isplaying = !isplaying;
    //监听播放進度
    flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);

    }
    //显示播放進度

    private function progressHandler(event:VideoEvent):void
    {
    hs.value = flv_video.playheadTime;
    if(flv_video.playheadTime == flv_video.totalTime)
    {
    flv_video.pause();
    play_btn.label="播放";
    isplaying = false;
    }
    }

        private function mousePress(event:MouseEvent):void
        {
            if(flv_video.playing)
            {
                flv_video.pause();
            }
            mouseUp(event);
        }
        private function mouseUp(event:MouseEvent):void
        {
            flv_video.playheadTime = hs.value;
            if(isplaying)
            {
                flv_video.play();
            }
            else
            {
                if(flv_video.playing)
                {
                    flv_video.pause();
                }
    
            }
        }
        //拖动进度条暂停播放
        private function thumbPress(event:SliderEvent):void
        {
            if(flv_video.playing)
            {
                flv_video.pause();
            }
    
        }
        //播放完成歸零
        private function thumbChanges(event:SliderEvent):void
        {
            if(flv_video.playheadTime == -1)
            {
                hs.value = 0;
                return;
            }
            playPosition = hs.value;//拖动目标位置开始播放
    
        }
        private function clickhshandler():void
        {
            if(flv_video.playheadTime == -1)
            {
                hs.value = 0;
                return;
            }
    

    // flv_video.playheadTime = hs.mouseX;
    flv_video.playheadTime = playPosition;//拖动目标位置开始播放

            if(isplaying)
            {
                flv_video.play();
            }
            else
            {
                if(flv_video.playing)
                {
                    flv_video.pause();
                }
    
            }
        }
        //調整播放進度      
        private function thumbRelease(event:SliderEvent):void
        {
            flv_video.playheadTime = playPosition;
            if(isplaying)
            {
                flv_video.play();
            }
            else
            {
                if(flv_video.playing)
                {
                    flv_video.pause();
                }
    
            }
        }
    
        //调整声音
        private function sound_thumbChanges(event:SliderEvent):void
        {
            soundPosition = hs_sound.value;
        }         
        private function sound_thumbRelease(event:SliderEvent):void
        {
            flv_video.volume = soundPosition;
        }
        //格式化時間
        private function formatTimes(value:int):String
        {
            if(value == -1)
            {
                value = 0;
            }
            var result:String = (value % 60).toString();
            if (result.length == 1)
            {
                result = Math.floor(value / 60).toString() + ":0" + result;
            }
            else 
            {
                result = Math.floor(value / 60).toString() + ":" + result;
            }
            return result;
        }
        //切換全屏顯示
        private function display():void 
        {   
    

    // if(fs.selected)//全屏
    // {
    // stage.displayState = StageDisplayState.FULL_SCREEN;
    // }
    // else
    // {

    // stage.displayState = StageDisplayState.NORMAL;
    // }
    if(stage.displayState == StageDisplayState.NORMAL)//全屏
    {
    stage.displayState = StageDisplayState.FULL_SCREEN;
    }
    else
    {

    stage.displayState = StageDisplayState.NORMAL;
    }
    }
    //缓冲的时候播放loading
    private function playLoading(flag:Boolean):void{
    if(flag)
    {//当缓冲时候
    // swfLoading.visible=true;
    // swfLoading.includeInLayout=true;
    flv_video.visible=false;
    flv_video.includeInLayout=false;
    }
    else
    {
    // swfLoading.visible=false;
    // swfLoading.includeInLayout=false;
    flv_video.visible=true;
    flv_video.includeInLayout=true;
    }
    }

        private function stateChangeEvent(event:VideoEvent):void
        {
            if(event.state==VideoEvent.BUFFERING||event.state==VideoEvent.LOADING)
            {//缓冲和加载
                playLoading(true);
            }
            else
            {
                playLoading(false);
            }
        }
        public function metadataReceivedHandler(event:Event):void {
            if (isNaN(flv_video.totalTime) || flv_video.totalTime == 0) {
                 var total_time:Number = flv_video != null ? flv_video.totalTime : NaN;
                 hs.maximum = total_time;
    
            }
            if (playPosition > -1) {
                flv_video.playheadTime = playPosition;
                flv_video.play();
                //监听播放進度 
                flv_video.addEventListener(VideoEvent.PLAYHEAD_UPDATE, progressHandler);
            }
        }
    

    // var timeID:int = setInterval(setTotalTime, 300);
    // function setTotalTime():void{
    // if(!flv_video.totalTime){
    // playtime.text = formatTimes(flv_video.playheadTime) +" : 总时间0";
    // }else{
    // clearInterval(timeID);
    // playtime.text = formatTimes(flv_video.playheadTime) +" : 总时间" +formatTimes(flv_video.totalTime);
    // }
    //

    // }

    // public function getTotalTime(evt:Event):void {
    // if (video_totalTime == 0 && !isNaN(flv_video.totalTime) && flv_video.totalTime > 0 ) {
    // video_totalTime = flv_video.totalTime;
    // playtime.text = formatTimes(flv_video.playheadTime)+" : 总时间" +formatTimes(flv_video.totalTime);
    // trace("playtime text: " + playtime.text);
    // }
    // }
    ]]>
    /mx:Script

    <mx:VBox width="100%" height="100%" horizontalAlign="center" verticalGap="0" verticalAlign="top" >
    
        <mx:VideoDisplay  id="flv_video"  width="800" height="600"  
            autoPlay="true" autoRewind="true" bufferTime="100"
            maintainAspectRatio="true" metadataReceived="metadataReceivedHandler(event)"
            stateChange="stateChangeEvent(event)" />
        <mx:HSlider id="hs" fillColors="#000099, #0000ff, #ffffff, #eeeeee" 
            showTrackHighlight="true" minimum="0" maximum="{flv_video.totalTime}" 
            thumbPress="thumbPress(event)" thumbRelease="thumbRelease(event)" 
            change="thumbChanges(event)" width="90%"  /><!--  mouseDown="mousePress(event)" mouseUp="mouseUp(event)"  click="clickhshandler()" -->
        <mx:ApplicationControlBar width="100%" height="38" horizontalAlign="center" >
            <mx:ApplicationControlBar width="123" cornerRadius="15">
                <mx:Button id="play_btn" click="flvplay(event)" label="播放" cornerRadius="13"/>
                <mx:Button id="stop_btn" label="停止" cornerRadius="13" click="flv_video.stop();play_btn.label='播放';hs.enabled=false;" />
            </mx:ApplicationControlBar>
            <mx:ApplicationControlBar width="132" cornerRadius="15" horizontalAlign="center">
                <mx:Label id="playtime" text="{formatTimes(flv_video.playheadTime)} : 总时间{formatTimes(flv_video.totalTime)}" 
                    width="100%" fontSize="12" textAlign="center"/>
            </mx:ApplicationControlBar>
            <mx:ApplicationControlBar cornerRadius="15" width="130">
                <mx:Label id="sound" text="声音" width="32" fontWeight="bold" fontSize="12" textAlign="center"/>
                <mx:HSlider id="hs_sound" width="86" minimum="0" maximum="1" thumbRelease="sound_thumbRelease(event)" 
                    change="sound_thumbChanges(event)" value="{flv_video.volume}"  fillAlphas="[0.6, 1.0, 1.0, 1.0]"/>
            </mx:ApplicationControlBar>
            <mx:ApplicationControlBar>
                <mx:CheckBox label="全屏" id="fs" change="display();" selected="false"/>
            </mx:ApplicationControlBar>
        </mx:ApplicationControlBar>
    </mx:VBox>
    

    /mx:TitleWindow

    点赞 1 评论 复制链接分享
  • wenpinglaoyao 纹枰老妖 2015-06-24 02:12

    请问主把问题详细描述一下,比如代码,截图等等,谢谢

    点赞 评论 复制链接分享
  • qq_29192379 qq_29192379 2015-06-24 07:48

    <mx:VideoDisplay  id="flv_video"  width="800" height="600"  
        autoPlay="true" autoRewind="true" bufferTime="100"
        maintainAspectRatio="true" metadataReceived="metadataReceivedHandler(event)"
        stateChange="stateChangeEvent(event)" />
    <mx:HSlider id="hs" fillColors="#000099, #0000ff, #ffffff, #eeeeee" 
        showTrackHighlight="true" minimum="0" maximum="{flv_video.totalTime}" 
        thumbPress="thumbPress(event)" thumbRelease="thumbRelease(event)" 
        change="thumbChanges(event)" width="90%"  /><!--  mouseDown="mousePress(event)" mouseUp="mouseUp(event)"  click="clickhshandler()" -->
    <mx:ApplicationControlBar width="100%" height="38" horizontalAlign="center" >
        <mx:ApplicationControlBar width="123" cornerRadius="15">
            <mx:Button id="play_btn" click="flvplay(event)" label="播放" cornerRadius="13"/>
            <mx:Button id="stop_btn" label="停止" cornerRadius="13" click="flv_video.stop();play_btn.label='播放';hs.enabled=false;" />
        </mx:ApplicationControlBar>
        <mx:ApplicationControlBar width="132" cornerRadius="15" horizontalAlign="center">
            <mx:Label id="playtime" text="{formatTimes(flv_video.playheadTime)} : 总时间{formatTimes(flv_video.totalTime)}" 
                width="100%" fontSize="12" textAlign="center"/>
        </mx:ApplicationControlBar>
        <mx:ApplicationControlBar cornerRadius="15" width="130">
            <mx:Label id="sound" text="声音" width="32" fontWeight="bold" fontSize="12" textAlign="center"/>
            <mx:HSlider id="hs_sound" width="86" minimum="0" maximum="1" thumbRelease="sound_thumbRelease(event)" 
                change="sound_thumbChanges(event)" value="{flv_video.volume}"  fillAlphas="[0.6, 1.0, 1.0, 1.0]"/>
        </mx:ApplicationControlBar>
        <mx:ApplicationControlBar>
            <mx:CheckBox label="全屏" id="fs" change="display();" selected="false"/>
        </mx:ApplicationControlBar>
    </mx:ApplicationControlBar>
    

    /mx:VBox

    点赞 评论 复制链接分享
  • qq_29192379 qq_29192379 2015-06-24 07:50

    不带表名 select 1+1 就行

    点赞 评论 复制链接分享

相关推荐