﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-java-god-随笔分类-flex</title><link>http://www.blogjava.net/java-god/category/29682.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 08 Mar 2008 12:22:48 GMT</lastBuildDate><pubDate>Sat, 08 Mar 2008 12:22:48 GMT</pubDate><ttl>60</ttl><item><title>自己写的一个播放器，还不是很完美，有空了再改</title><link>http://www.blogjava.net/java-god/archive/2008/02/24/181769.html</link><dc:creator>java flex 结合</dc:creator><author>java flex 结合</author><pubDate>Sun, 24 Feb 2008 06:47:00 GMT</pubDate><guid>http://www.blogjava.net/java-god/archive/2008/02/24/181769.html</guid><wfw:comment>http://www.blogjava.net/java-god/comments/181769.html</wfw:comment><comments>http://www.blogjava.net/java-god/archive/2008/02/24/181769.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/java-god/comments/commentRss/181769.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/java-god/services/trackbacks/181769.html</trackback:ping><description><![CDATA[&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" <br />
&nbsp;&nbsp;   width="410"<br />
&nbsp;&nbsp;   height="310"<br />
&nbsp;&nbsp;   layout="absolute" &gt;<br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
&nbsp;&nbsp;   import mx.events.SliderEvent; // 这里是导入所需要的类, 用 import 关键字, 没什么好说的<br />
&nbsp;&nbsp;   import mx.events.VideoEvent;<br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;   // 自定义一个 playingMove() 函数, 作用: 影片播放时, id 为 " my_hs " 的HSlider 控件的值为影片的播放时间, 且最大值为影片的总时长<br />
&nbsp;&nbsp;   private function playingMove(event:VideoEvent):void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  my_hs.value = flvideo.playheadTime;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  my_hs.maximum=flvideo.totalTime;<br />
&nbsp;&nbsp;   }<br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;   // 自定义 hs_onChange() 函数, 作用: 当用户拖拉 HSlider 控件使其值发生改变时,  影片的播放头就处于其值处, 即正在播放时间处于其值处<br />
&nbsp;&nbsp;   private function hs_onchange(event:SliderEvent):void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  flvideo.playheadTime = event.value;<br />
&nbsp;&nbsp;   }<br />
&nbsp;&nbsp;  &nbsp;&nbsp;   <br />
&nbsp;&nbsp;   //停止<br />
&nbsp;&nbsp;&nbsp;  private function stopMovie(event:MouseEvent):void{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  flvideo.stop();<br />
&nbsp;&nbsp;&nbsp;  }<br />
&nbsp;&nbsp;   //播放<br />
&nbsp;&nbsp;&nbsp;  private function playMovie(event:MouseEvent):void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   playUrl(flvideo.source);<br />
&nbsp;&nbsp;&nbsp;  }<br />
&nbsp;&nbsp;   //暂停<br />
&nbsp;&nbsp;&nbsp;  private function pauseMovie(event:MouseEvent):void{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  flvideo.pause();<br />
&nbsp;&nbsp;&nbsp;  }<br />
<br />
&nbsp;&nbsp;&nbsp;  private function playUrl(url:String):void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   if(flvideo.playing)<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;    &nbsp;&nbsp;&nbsp;   flvideo.stop();<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  flvideo.source = url;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  flvideo.play();<br />
&nbsp;&nbsp;&nbsp;  }<br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;&nbsp;  private function displayStateChange():void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   var flag:int=1;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   if(stage.displayState == StageDisplayState.FULL_SCREEN){<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.width=410;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.height=310; <br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   stage.displayState = StageDisplayState.NORMAL;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   }else{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.width=Capabilities.screenResolutionX;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.height=Capabilities.screenResolutionY;<br />
&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   stage.displayState = StageDisplayState.FULL_SCREEN;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   }<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   if(flag!=2){<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   stage.addEventListener(FullScreenEvent.FULL_SCREEN ,fullScreenHandler);<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   flag=2;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   }<br />
&nbsp;&nbsp;&nbsp;  }<br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;   private function fullScreenHandler(event:FullScreenEvent):void{<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   if(!event.fullScreen){<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.width=410;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   this.height=310;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   }<br />
&nbsp;&nbsp;   }<br />
<br />
<br />
]]&gt;<br />
&lt;/mx:Script&gt;<br />
&nbsp;&nbsp;   &lt;!-- complete="this.flvideo.play()" 重复播放--&gt;<br />
&nbsp;&nbsp; &lt;mx:VideoDisplay id="flvideo" playheadUpdate="playingMove(event)"
source="Butterfly.flv" left="10" right="10" top="10" bottom="55"/&gt;<br />
&nbsp;&nbsp;   <br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:Button label="Play" x="10" y="279" width="60" click="playMovie(event)"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:Button x="81" y="279" label="stop" width="60" click="stopMovie(event)"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:Button x="266" y="279" label="pause" width="60" click="pauseMovie(event)"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:Label x="1" y="258" text="progress：" width="72" textAlign="right"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:Button x="341" y="279" label="full" width="60" click="displayStateChange()"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:HSlider  minimum="0"  id="my_hs"  change="hs_onchange(event)"&nbsp;&nbsp;  x="70" y="262"  width="210"/&gt;<br />
&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp;   &lt;mx:HSlider x="320" y="262" width="88"/&gt;<br />
&nbsp;&nbsp;   <br />
&lt;/mx:Application&gt;
<img src ="http://www.blogjava.net/java-god/aggbug/181769.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/java-god/" target="_blank">java flex 结合</a> 2008-02-24 14:47 <a href="http://www.blogjava.net/java-god/archive/2008/02/24/181769.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>