如何在 python 脚本中使用 HTML5 从网站播放 link 中的视频?

How to play video in a link from website using HTML5 in my python script?

我有这个 python 脚本代码,我在 apache 中使用 wsgi 模块。 table 有 id 和 video_filename。

video_filename 每行包含一个文件名。每个文件名都是一个视频文件名。视频文件名的扩展名为 .mp4。例如:

ID video_filename ………… 4 视频4.mp4 3 视频3.mp4 2 视频2.mp4 1 个视频 1.mp4

我的数据库中的视频数量每天都会自动增加table。这已经在我已经完成的其他脚本中完成了。

使用此 python 脚本,我显示了一个 table ID 为视频文件名。

import sqlite3
def application(environ, start_response):

 db = sqlite3.connect('/var/www/html/table.db')
 db.row_factory = sqlite3.Row
 cursor = db.cursor()
 cursor.execute('''SELECT id, video_filename FROM table ORDER BY id DESC''')
 results = ['<table><th>id</th><th>video_filename</th>']
 for row in cursor:
  results.append('<tr>')
  results.append('<td>{0}</td>'.format(row['id']))
  results.append('<td>{0}</td>'.format(row['video_filename'])
  results.append('</tr>')
 db.close()
 results.append('</table>')

 headers = [
 ('Content-Type', 'text/html; charset=utf-8'),
 ('Content-Length', str(sum(len(line) for line in results)))
 ]

 start_response('200 OK', headers)

 return results

此代码有效。

我想要的是只在用户点击特定视频文件名时显示视频。我知道我必须使用 HTML5 视频控制器标签。但我不知道该怎么做。

文件名视频记录在数据库中但也保存在/var/www/html/

例如:

/var/www/html/video1.mp4

有什么帮助吗?

如果我在 link 中单击时会弹出特定的视频文件名,那就太好了。当我关闭视频然后像以前一样回到 table id video_filename。

制作一个 javascript 函数,将视频加载到 HTML,单击视频名称所在的 table 单元格时将激活它。

results.append('<td onClick="playVideo({0});">{0}</td>'.format(row['video_filename'])

在 JS 中:

function playVideo(name) {
    var urlPrefix = window.location.href + '/var/www/html/',
          url = urlPrefix + name;
    alert(url);
    // load url to html video tag
}