前端按钮预临览mp4的后台调用方法
def open_record(self): """查看文件""" pdfid = self.shh_shengchbg(self.file_id.id) # print('加文件id', self.file_id.id) # print(pdfid) # http://localhost:8069 if pdfid: drbz = { 'body': self.env.user.name + fields.Datetime.to_string(fields.Datetime.now()+datetime.timedelta(hours=8))+ '查看该文件一次' , 'record_name': self.name, 'model': 'dms.file', 'res_id': self.file_id.id, 'date': fields.datetime.now(), 'message_type': 'comment', 'subtype_id': 2, "add_sign": True } self.env['mail.message'].sudo().create(drbz) myurl = '/dms/static/src/pdfjs/vieweroncs.html?file=/web/content/' + \ str(pdfid) + '?model%3Dir.attachment' return { 'type': 'ir.actions.act_url', 'url': myurl, 'target': 'new', 'res_id': pdfid, } else: # 视频文件,无附件id return { 'type': 'ir.actions.act_url', 'url': '/dms/preview?mpname='+str(self.file_id.id), 'target': 'new', 'res_id': 0, }
通过controler中main.py传递至前端网页
@http.route("/dms/preview", auth="public") def preview(self): # headers = {'Cache-Control': 'no-store','Expires':0} # print('/dms/preview', request.httprequest.url) wjm="/dms/mp4/"+request.httprequest.url.split('=')[1]+'.m3u8' # print('wenjm',wjm,npname) # temp模板文件,数据参数传递 response = request.render('dmssp.myplayer', {'mdata':wjm})
前端通过t-all-src="mdata"传递
<video id="player" class="video-js vjs-default-skin " controls="preload" > <!-- style="width:800px;margin: auto;"--> <source id="ss" t-att-src="mdata" type="application/x-mpegURL"/> </video>
js文件通过分解目录 ,定时从服务器缓存文件,播放文件