用webpy+gae做一个隐藏播放文件地址的东东,失败了

 很简单

想把一些mp3文件放到gae上,不过不想被下载,虽然不是什么歌之类的

 

于是选了个html5的播放器

jplayer

 

http://jplayer.org/

 

demo代码 <!DOCTYPE html>

<html lang="en">
    <head>
        
        <!-- Example code to create a simple player using jPlayer 2.1.0 -->
        
        <!-- Skins are defined in CSS. Uncomment the following CSS reference and comment out the one below it to switch skins -->
        
        <!--<link href="http://jplayer.org/latest/skin/blue.monday/jplayer.blue.monday.css" rel="stylesheet" type="text/css" />--> 
        <link href="http://jplayer.org/latest/skin/pink.flag/jplayer.pink.flag.css" rel="stylesheet" type="text/css" />
        
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>    
        <script type="text/javascript" src="http://jplayer.org/2.1.0/js/jquery.jplayer.min.js"></script>
        <script type="text/javascript">
            
            $(document).ready(function() {

    $("#jquery_jplayer_1").jPlayer({
        ready: function(event) {
            $(this).jPlayer("setMedia", {
                 <!--mp3: "12.mp3" -->       
                 mp3: "http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3"
            });
        },
        swfPath: "http://www.jplayer.org/2.1.0/js",
        supplied: "mp3"
    });
});   
              
        </script>
        
    </head>
    <body>
        <div id="jquery_jplayer_1" class="jp-jplayer"></div>
        
        <div id="jp_container_1" class="jp-audio">
            <div class="jp-type-single">
                <div class="jp-gui jp-interface">
                    <ul class="jp-controls">
                        
                        <!-- comment out any of the following <li>s to remove these buttons -->
                        
                        <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
                        <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
                        <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
                        <li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li>
                        <li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li>
                        <li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li>
                    </ul>
                    
                    <!-- you can comment out any of the following <div>s too -->
                    
                    <div class="jp-progress">
                        <div class="jp-seek-bar">
                            <div class="jp-play-bar"></div>
                        </div>
                    </div>
                    <div class="jp-volume-bar">
                        <div class="jp-volume-bar-value"></div>
                    </div>
                    <div class="jp-current-time"></div>
                    <div class="jp-duration"></div>                   
                </div>
                <div class="jp-title">
                    <ul>
                        <li>Cro Magnon Man</li>
                    </ul>
                </div>
                <div class="jp-no-solution">
                    <span>Update Required</span>
                    To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.
                </div>
            </div>
        </div>
        
        
    </body>​

 

 

结果,无论是上述例子中用demo的mp3url,还是用本地的mp3文件,都表现正常

 

一旦用gae

 

就会报上篇文章的错误,chrome的快进功能失效,ff和maxthon3正常(废话,他们是同一个核心)

 

当然 yaml文件里要做类似如下修改

 

 

- url: /audio/(.*\.(mid|midi|mp3|wav))

  static_files: audio/\1

  upload: audio/(.*\.(mid|midi|mp3|wav))

 

 

 

到此为止,我已经失败了,因为即使我把mp3的地址暴露出来都不行的话,还继续研究个啥呢

 

不过还是坚持了一小把,算是为将来留个念头

 

思路

 

在test.html中的mp3地址设置中

 

设置为如下形式

 

mp3: "12.mp3"

 

 

当进入html的时候,js会去请求127.0.0.1:8085/12.mp3的url

 

在code.py中设置

 

    '/(.*\.mp3)' ,       'audio',

 

 

 

在audipclass中设置

 

 

    def GET(self,name):
         client = ''
         client =  web.ctx.env.get('HTTP_REFERER') 
         if (not client  == None ) and  client.endswith('test'):                 
           newurl = 'http://127.0.0.1:8085/audio/' + name    
           logging.info("newurl ::::::" + newurl)
           raise web.redirect(newurl)           
         else :  
           return  'stop download '
 

 

当然,在yaml中,要把audio的文件夹设为static

 

换句话说,这个过程是

表面上test.html发出的请求是127.0.0.1:8085/1.mp3

接受这个请求的是audioc这个class,如果HTTP_REFERER的结尾时test,

则redirect到127.0.0.1:8085/audio/1.mp3上

否则,返回字符 'stop download '

 

这个过程倒是用chrome验证成功了,除了不能快进快退

 

但是ff和maxthon却失败了,用firebug查看的结果,发出127.0.0.1:8085/1.mp3后没有得到相应

哎,莫非ff只能一次性响应不成?

算了,这个周末到此为止

下一步,换个html5播放器试试。

 

 

》》》第二天,成功了,见下一篇,虽然不完美

 

你可能感兴趣的:(webpy)