2016-03-17 64 views
0

我想創建一個簡單的web服務器與蟒蛇扭曲。儘管如此,我仍然無法提供m4a音頻文件。Python扭曲的web服務器音頻文件

在當前程序中,當我加載http://localhost:8880/mp3.html時,它工作正常。它顯示音頻播放器和mp3播放。另外,該程序打印「/mp3.html」和「/test.mp3」。

但是,當我加載http://localhost:8880/m4a.html時,它不起作用。它顯示音頻播放器,但m4a不播放。另外,該程序僅打印「/m4a.html」而不打印「/test.m4a」。

我目前的代碼如下。

import urlparse 
import os 
from twisted.internet import reactor 
from twisted.web.server import Site 
from twisted.web.resource import Resource 
from twisted.web.static import File 
import time 
import subprocess 
import mimetypes 

class playM4A(Resource): 
    isLeaf = True 
    def render_GET(self, request): 
     this=urlparse.urlparse(request.path)#scheme,netloc,path,query 
     root,ext=os.path.splitext(this.path) 
     filename=os.path.basename(request.path) 
     fileFolder=request.path.replace(filename,"") 
     self.serverRoot=os.getcwd() 
     print request.path 
     if ext==".m4a": 
      thisFile=File(self.serverRoot+request.path) 
      return File.render_GET(thisFile,request) 
     elif ext==".mp3": 
      thisFile=File(self.serverRoot+request.path) 
      return File.render_GET(thisFile,request) 
     elif filename=="m4a.html": 
      return """ 
<html> 
<audio controls> 
    <source src="http://localhost:8880/test.m4a" type="audio/mp4a-latm"> 
Your browser does not support the audio element. 
</audio> 
not m4a </html>""" 
     elif filename=="mp3.html": 
      return """ 
<html> 
<audio controls> 
    <source src="http://localhost:8880/test.mp3" type="audio/mp3"> 
Your browser does not support the audio element. 
</audio> 
not m4a </html>""" 

resource = playM4A() 
factory = Site(resource) 
reactor.listenTCP(8880, factory) 
reactor.run() 
+0

這似乎與MP3的工作,所以我認爲它可能有一些做的M4A文件格式。 – user1763510

+0

我懷疑'Content-Type:'標題不正確。你可以使用wget,curl,Python請求或其他方便的工具來確定M4A GET和MP3 GET返回的內容類型嗎? –

+0

你還使用什麼操作系統?什麼瀏覽器? –

回答

0

代碼工作,如果你改變音頻/ MP4A-LATM音頻/ MP4