FLEX编写播放器(防止下载与嗅探)

来源:互联网 发布:百度音乐mac版下载 编辑:程序博客网 时间:2024/04/30 05:14

运行预览近一段时间从零开始接触Flex 最后做成了一个有点意思的播放器 下面是整个工作的流程
1.需求 防止用户保存(包括缓存) 下载 嗅探的播放器一个
 尝试用activex控件 联想到网络播放的需求 认为流媒体格式更加合适这个播放器 转而寻找新的解决方法
 通过资料查询,发现Adobe公司的FLEX很适合开发这样的播放器 特别是加上FMS3.0的防下载机制 我就可以
更加轻松了 于是 通过对网上资源的修改 做成第一版播放器
<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="playinit()" width="500" height="400">


    <mx:Script>
    <![CDATA[
       import mx.events.SliderEvent;
       import mx.events.VideoEvent;
       import mx.collections.ArrayCollection;
       import mx.rpc.events.ResultEvent;
       import flash.display.Stage;
     
       private var _video:ArrayCollection;  
       private var isplaying:Boolean=false;     
       //private var video_url:String = "C:/video.flv";     
       private var playPosition:Number;     
       private var soundPosition:Number;
     
       private function readXml(event:ResultEvent):void{
       _video = event.result.videos.video;
             }  

       private function playinit():void{
        hs.enabled=false;
       }
     
       private function flvplay(event:Event):void{
            var query:String = ExternalInterface.call("window.location.search.substring", 1);
            if(query) {     
                    var pos:int = query.indexOf("=");
                    //Alert.show(String(pos));
                    if(pos != -1) {
                        var value:String = query.substr(pos+1);
                         }
                }
           
      flv_video.source="rtmp://localhost/vod/media/"+value+".flv";
       //flv_video.source="c:/vedio.flv";
        hs.enabled=true;
        if(isplaying){
         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;
       }
         
       private function thumbPress(event:SliderEvent):void{
        flv_video.pause();
       }
       private function thumbChanges(event:SliderEvent):void{
        if(flv_video.playheadTime == -1){
      hs.value = 0;
      return;
     }
        playPosition = hs.value;
       }     
       private function thumbRelease(event:SliderEvent):void{
        flv_video.playheadTime = playPosition;
        if(isplaying){
         flv_video.play();
        }else{
         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{
        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.fullScreenSourceRect =new Rectangle(flv_video.x,flv_video.y,flv_video.width,flv_video.height);            
                 //  stage.displayState="fullScreen";
                   stage.displayState =StageDisplayState.FULL_SCREEN;
                    //application.width="100%";
                    //application.height="100%"
                }
                else
                {  
                    //stage.displayState="normal";  
                    stage.displayState = StageDisplayState.NORMAL;
                }  
            }
           
    ]]>
    </mx:Script>
<mx:VideoDisplay   id="flv_video" x="0" width="100%" height="332" y="0" source="{Application.application.parameters.movie}" autoPlay="false" autoRewind="true" bufferTime="0.5" maintainAspectRatio="false" />
<mx:ApplicationControlBar height="20" width="100%" bottom="53" x="0" horizontalAlign="center">
   <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%" horizontalCenter="0"/>
</mx:ApplicationControlBar>
<mx:ApplicationControlBar width="100%" height="38" horizontalAlign="center" x="0" bottom="10">
   <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="94" cornerRadius="15">
    <mx:Label id="playtime" text="{formatTimes(flv_video.playheadTime)} : {formatTimes(flv_video.totalTime)}" color="#ffffff" width="77"/>
   </mx:ApplicationControlBar>
   <mx:ApplicationControlBar cornerRadius="15" width="100">
    <mx:HSlider id="hs_sound" width="82" minimum="0" maximum="1" thumbRelease="sound_thumbRelease(event)" change="sound_thumbChanges(event)" value="{flv_video.volume}" />
   </mx:ApplicationControlBar>
   <mx:ApplicationControlBar color="#EC968F">
    <mx:CheckBox label="全屏" id="fs" change="display();"/>
   </mx:ApplicationControlBar>
</mx:ApplicationControlBar>
</mx:Application>

 

其中播放器播放源文件的路径是默认安装FMS3.0之后在

C:/Program Files/Adobe/Flash Media Server 3/applications/vod/media 之中。调用方式是flv_video.source="rtmp://localhost/vod/vedio.flv";可以通过修改配置文件改变视频存放目录


播放器的代码大多来自网上 只是有几点修改

第一 取得路径 由于安全机制 播放器只能通过服务器地址取值

第二 全屏问题
<param name="allowFullScreen" value="true" /> 
全屏时播放器大小不变
<mx:VideoDisplay   id="flv_video" x="0" width="100%" height="90%" y="0" source="{Application.application.parameters.movie}" autoPlay="false" autoRewind="true" bufferTime="0.5" maintainAspectRatio="false" />
width="100%" height="90%"十分重要 这将会与
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="playinit()" width="500" height="400">密切相关


最终解决方法
stage.fullScreenSourceRect =new Rectangle(flv_video.x,flv_video.y,flv_video.width,flv_video.height);
第三 播放flv视频时不留下缓存
http://etoaoo.javaeye.com/blog/341345

这个版本中的基本功能都可以实现 但是最后发现一个巨大的问题

可以被嗅探 Replay Media Catcher

这个软件通过记录网络包 并且以相同网络包给FMS服务器发包 骗取服务器的数据 然后自己一段一段组装成流媒体视频 这个漏洞几乎宣布了项目的死刑

不过解决方案很快就出来了

未完......