我的在线视频阅读器无法正常工作。有啥建议?
Posted
技术标签:
【中文标题】我的在线视频阅读器无法正常工作。有啥建议?【英文标题】:My online video reader is not working. Any suggestions?我的在线视频阅读器无法正常工作。有什么建议? 【发布时间】:2021-11-18 23:47:53 【问题描述】:我的html
代码由于某种原因无法正常工作。我的 HTML 包括:
<input type="file" id="upload" accept=".mp4,.webm, .mov"/><br>
<video id="video" controls>
<source src="" id="srcvideo" />
</video>
<script>
var y = document.getElementById("audio");
function handleFiles(event)
var files = event.target.files;
$("#srcvideo").attr("srcvideo", URL.createObjectURL(files[0]));
document.getElementById("video").load();
y.play();
</script>
但由于某种原因,此代码不显示视频。 我尝试使用与音频相同的代码,但它也不起作用。 如果你有任何 建议 请 回复! -谢谢,rxgkit
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" id="upload" accept=".mp4,.webm, .mov"/><br>
<video id="video" controls>
<source src="" id="srcvideo" />
</video>
<script>
var y = document.getElementById("audio");
function handleFiles(event)
var files = event.target.files;
$("#srcvideo").attr("srcvideo", URL.createObjectURL(files[0]));
document.getElementById("video").load();
y.play();
</script>
【问题讨论】:
【参考方案1】:您做错了几件事,没有将句柄文件链接到任何地方并将“y”指向“音频”而不是“视频”,但总体而言,您的代码几乎没问题。看看我的 sn-p 工作。
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.2.0/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" id="upload" accept=".mp4,.webm, .mov"/><br>
<video id="video" controls>
</video>
<script>
function handleFiles(event)
var y = document.getElementById("video");
var file = event.target.files[0];
y.src = URL.createObjectURL(file);
y.load();
y.play();
const inputFile = document.getElementById('upload')
inputFile.addEventListener('change', handleFiles);
</script>
【讨论】:
我认为提问者需要.src = (window.URL || window.webkitURL).createObjectURL(file);
但那是 javascript,我不确定 JQuery 等价物...以上是关于我的在线视频阅读器无法正常工作。有啥建议?的主要内容,如果未能解决你的问题,请参考以下文章