Django / HTML5音频标签不适用于特定文件

时间:2014-08-27 10:17:35

标签: python django html5

我从数据库中的base64编码数据生成一个mp3和一个ogg文件。
然后在Django模板中使用HTML代码

<audio controls="control">
             <source src="{{STATIC_URL}}audio/voice_{{each.id}}_.mp3" type="video/mp3">
             <source src="{{STATIC_URL}}audio/voice_{{each.id}}_.ogg" type='audio/ogg; codecs=vorbis'>
             <p>Your user agent does not support the HTML5 Audio element.</p>
</audio>

路径是对的。该文件也存在,但音频播放器出现,然后在一秒钟内从浏览器中消失。 我有一个示例mp3文件,所以只是为了测试我给了一个静态src路径,它工作正常。

这些base64编码/解码的mp3文件在我保存和播放后在本地工作,但不在浏览器中。
我想我可能正在解码并创建错误的文件,所以这里也是代码。

encoded_mp3_str = record.callRecord
decoded_mp3_str = base64.b64decode(encoded_mp3_str)
with open(settings.BASE_DIR+'/play/static/audio/voice_'+str(record.id)+'_'+ '.mp3', 'w') as mp3_file:
    mp3_file.write(decoded_mp3_str)
    mp3_file.close()
with open(settings.BASE_DIR+'/play/static/audio/voice_'+str(record.id)+'_'+ '.ogg', 'w') as ogg_file:
    ogg_file.write(decoded_mp3_str)
    ogg_file.close()

record是模型对象,record.callRecord是这样的:

AAAAGGZ0eXAzZ3A0AAAAAGlzb20zZ3A0AAAEHW1vb3YAAABsbXZoZAAAAADQI0y80CNMvAAAA+gAAAoUAAEAAAEAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAOpdHJhawAAAFx0a2hkAAAAB9AjTLzQI0y8AAAAAQAAAAAAAAoUAAAAAAAAAAAAAAAAAQAAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAADRW1kaWEAAAAgbWRoZAAAAADQI0y80CNMvAAAH0AAAFCgAAAAAAAAACxoZGxyAAAAAAAAAABzb3VuAAAAAAAAAAAAAAAA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