2011-02-08 123 views
0

有4個Videosource,以便用戶可以在視頻的同一進程之間切換。Flex 4 spark視頻播放器如何播放currentTime

我該如何執行此操作? 功能seek(time:duration):void dosn't真的有用。 :-(

,我用我的

代碼:

<?xml version="1.0" encoding="utf-8"?> 

<fx:Script> 
    <![CDATA[ 
     import mx.events.VideoEvent; 

     import org.osmf.media.MediaPlayer; 
     import org.osmf.video.CuePoint; 

     protected function button1_clickHandler(event:MouseEvent):void 
     { 
      var playing:Boolean=VideoPlr.playing; 
      var time:Number = VideoPlr.currentTime; 
      VideoPlr.source = "http://helpexamples.com/flash/video/water.flv"; 
      // dosn't work this.VideoPlr.seek(VideoPlr.duration * time/100); 
      if(playing) VideoPlr.play(); 
     } 


     protected function button2_clickHandler(event:MouseEvent):void 
     { 
      var playing:Boolean=VideoPlr.playing; 
      var time:Number = VideoPlr.currentTime; 
      VideoPlr.source = "http://helpexamples.com/flash/video/clouds.flv"; 
      // dosn't work this.VideoPlr.seek(VideoPlr.duration * time/100); 

      if(playing) VideoPlr.play(); 
     } 


     protected function button3_clickHandler(event:MouseEvent):void 
     { 
      var playing:Boolean=VideoPlr.playing; 
      var time:Number = VideoPlr.currentTime; 
      VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv"; 
      // dosn't work this.VideoPlr.seek(VideoPlr.duration * time/100); 
      if(playing) VideoPlr.play(); 
     } 


     protected function button4_clickHandler(event:MouseEvent):void 
     { 
      var playing:Boolean=VideoPlr.playing; 
      var time:Number = VideoPlr.currentTime; 
      //VideoPlr.source = "http://helpexamples.com/flash/video/cuepoints.flv"; 
      if(playing) VideoPlr.play(); 
     } 

    ]]> 
</fx:Script> 
<s:VideoPlayer x="26" y="10" height="588" width="1081" autoPlay="false" 
       source="http://helpexamples.com/flash/video/water.flv" 
       id="VideoPlr" muted="false" pauseWhenHidden="true" 

感謝你在期待

+0

你爲什麼`VideoPlr.duration * time/100`獲得你的尋找時間? – jswolf19 2011-02-08 11:49:01

回答

1

這裏是我的解決方案:

有四個文件可以在您的deisgne中切換。每個開關都會跳轉到新的源文件中。

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" 
       creationComplete="createHandler();"> 
    <s:layout> 
     <s:BasicLayout/> 
    </s:layout> 

    <fx:Script> 
     <![CDATA[ 
      import flash.events.TimerEvent; //very important 
      import flash.utils.Timer; //very important 

      import flashx.textLayout.events.UpdateCompleteEvent; 

      import mx.events.VideoEvent; 

      import org.osmf.events.MediaElementEvent; 
      import org.osmf.events.MediaPlayerStateChangeEvent; 
      import org.osmf.media.MediaPlayer; 
      import org.osmf.media.MediaPlayerState; 


      private var time:Number=0; 
      private var changed:Boolean = false; 

      protected function normal_clickHandler(event:MouseEvent):void 
      { 
       ini(); 
       Text.text = "current Tume: "+time 
       vid.source="1.flv" 
      } 
      protected function ini():void{ 
       if(vid.currentTime>0){ 
        time = Math.round(vid.currentTime); 
        changed = true; 
        timer.reset(); 
        timer.start(); 
       } 
      } 
      protected function nurhoer_clickHandler(event:MouseEvent):void 
      { 
       ini(); 
       vid.source="2.flv" 
       Text.text = "current Tume: "+time; 
      } 


      protected function schwerh_clickHandler(event:MouseEvent):void 
      { 
       ini(); 
       Text.text = "current Tume: "+time; 
       vid.source="3.flv" 
      } 

      protected function schwerhmH_clickHandler(event:MouseEvent):void 
      { 
       ini(); 
       Text.text = "current Tume: "+time; 
       vid.source="4.flv" 
      } 
      protected var timer:flash.utils.Timer = new Timer(200,2); 
      private function createHandler():void 
      { 
       try{ 
        timer.addEventListener(flash.events.TimerEvent.TIMER, repeat); 
        timer.addEventListener(flash.events.TimerEvent.TIMER_COMPLETE, repeat); 
        //console.text = "Events are loaded2!"; 
       }catch(exep){} 
      } 
      source="{source}" /> 
      private function repeat(event:flash.events.TimerEvent):void{ 
       if(!vid.playing){ 
       try{ 

         if(changed && Math.round(vid.currentTime)!= Math.round(time)){ 
//       console.text = console.text +"\n"+"try to seek to: "+time; 
          vid.seek(time); 
          changed=false; 
         }else { 
          timer.reset(); 
          timer.stop(); 
          vid.play(); 
         } 
        }catch (ex){} 

       } 
      } 





     ]]> 
    </fx:Script> 

感謝您的剋制。