为什么视频加载时间这么长?然后不玩了
Why is video taking so long to load? And then not playing
我正在编写 Python/Django 应用程序,我已经让用户能够加载存储在 /media/
目录中的视频文件。然后,当我尝试播放这些文件时,html 似乎首先尝试下载整个文件,即使完成后也不会播放视频。
HTML 上传表格
<form method="post" action="/admin/upload_file/" enctype="multipart/form-data">{% csrf_token %}
<table align="center">{{ form }}</table>
<input name="cid" hidden value="{{course.id}}" type="text">
<button class="btn btn-primary btn-sm">Upload Content</button>
</form>
Python 查看
def upload_file(request):
if request.method == 'POST':
form = ModelFormWithFileField(request.POST, request.FILES)
if form.is_valid():
# file is saved
form.save()
msg = "Successful upload"
else:
msg = "Invalid form"
else:
msg = "File not loaded"
return display_course(request, msg=msg, course = Course.objects.get(id=int(request.POST.get('cid'))))
HTML 播放
<video width="854" height="480" controls>
<source src="../media/{{module.module_key.url}}" type="video/mp4">
</video>
首先,Django内置的服务器不支持mp4文件播放(需要一些技巧)。
其次,某些 mp4 文件不可播放。
你可以试试:
- 使用 nginx 或其他网络服务器来提供文件
- 确保 mp4 文件可以流式传输。
我正在编写 Python/Django 应用程序,我已经让用户能够加载存储在 /media/
目录中的视频文件。然后,当我尝试播放这些文件时,html 似乎首先尝试下载整个文件,即使完成后也不会播放视频。
HTML 上传表格
<form method="post" action="/admin/upload_file/" enctype="multipart/form-data">{% csrf_token %}
<table align="center">{{ form }}</table>
<input name="cid" hidden value="{{course.id}}" type="text">
<button class="btn btn-primary btn-sm">Upload Content</button>
</form>
Python 查看
def upload_file(request):
if request.method == 'POST':
form = ModelFormWithFileField(request.POST, request.FILES)
if form.is_valid():
# file is saved
form.save()
msg = "Successful upload"
else:
msg = "Invalid form"
else:
msg = "File not loaded"
return display_course(request, msg=msg, course = Course.objects.get(id=int(request.POST.get('cid'))))
HTML 播放
<video width="854" height="480" controls>
<source src="../media/{{module.module_key.url}}" type="video/mp4">
</video>
首先,Django内置的服务器不支持mp4文件播放(需要一些技巧)。
其次,某些 mp4 文件不可播放。
你可以试试:
- 使用 nginx 或其他网络服务器来提供文件
- 确保 mp4 文件可以流式传输。