我想允許用戶在我的網站上傳視頻,並且我希望在提交表單之前顯示視頻預覽。在提交表單前顯示視頻
我做到了與圖像,但對於視頻中的腳本不能正常工作
HTML:
<div class="preview">
<a href="#" id="close-vid" class="close-button" role="button">
<span class="glyphicon glyphicon-remove-circle"></span>
</a>
\t
<video id="vid1" width="200" height="200" controls>
\t \t \t <source src="#" id="vid-src" type="video/*">
\t \t \t \t \t Your browser does not support HTML5 videos
\t </video> \t
\t \t \t \t \t \t \t
</div>
<label for="upload-vid1">
<span class="glyphicon glyphicon-film" role="button" ></span>
\t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t \t
<input type="file" id="upload-vid1" name="media-vid"
class="hidden upload-vid file_multi_video" accept="video/*">
\t \t \t \t Videos
\t </label>
用於預覽的DIV
的PHP:
$("#upload-vid1").on("change", function(){
var this_ = $(this).parent();
var dataid = $(this).attr('data-id');
var files = !!this.files ? this.files : [];
if (!files.length || !window.FileReader) return;
\t \t \t
\t if (/^video/.test(files[0].type)){
\t var reader = new FileReader();
\t \t reader.readAsDataURL(files[0]);
\t \t reader.onloadend = function(){
\t \t \t \t \t
\t \t \t var video = document.getElementById('vid-src');
\t \t \t video.src = this.result;
\t \t \t $("#vid1").show();
\t \t \t \t }
\t \t \t }
\t \t });
我想你想運行從本地文件系統文件的視圖:// C:\路徑\爲\視頻\文件\ on \ disk,它應該用JS完成。唉,從來沒有做過我自己,所以由你來想象如果可能 –
https://stackoverflow.com/questions/8885701/play-local-hard-drive-video-file-with-html5-video-tag - 對於工作示例查看jsfiddle中已接受的答案 –
謝謝@Evil_skunk – Dilak