如何将海报添加到多个视频列表中的特定视频元素
我想在特定视频元素上添加 poster
标签,其中该特定视频的 src
会导致 404
错误。
进一步解释一下: 我从数据库中查询了一个视频列表,其中一些可能会导致 404
错误,这意味着视频文件未正确上传,我的目标是向这些视频添加一个 poster
标签视频,以便我可以区分正常工作的视频和无法正常工作的视频
从数据库获取视频
<?
$storage = new ObjectStorage;
$db->query("SELECT videoId, videoVsId, videoFile, videoUploadTime FROM videos WHERE vidOjId='$jbId' AND videoArchived = '0000-00-00 00:00:00' AND videoFile LIKE '%/videos/uploaded_videos/items/%'");
$i = 0;
while ($db->next_record()) {
list($videoId, $videoVsId, $videoFile, $vidUploaded) = $db->Record;
$vidname = after("_video_", $videoFile);
$url = "https://website.website.com$videoFile";
if($vidUploaded) {
$vidUploaded = "Uploaded: ".date("H:i d/m/Y", strtotime($vidUploaded));
} else {
$vidUploaded = "Last edited: ".date("H:i d/m/Y", filemtime("../uploaded_videos/".$videoFile));
}
$brokenPoster = "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png";
然后我检查网址是否已损坏
if(@file_get_contents($url)){
$brokenPoster = "";
} else {
$brokenPoster;
}
此时我不知道该怎么做,我有什么到目前为止所做的如下
?>
<div class="videoDiv_<?= $vidId ?>">
<div class="videosDiv" >
<video id="allVideos" width="320" height="240" controls
poster="<?= $brokenPoster?>"
class="img_<?= $videoId?>" src="<?= $videoFile."?nocache=".rand()?>"
type="video/mp4">
</video>
</div>
</div>
<? $i++; } ?>
显然上面将将海报显示给所有 6 个视频元素,其中只有 2 个无法播放 404。
有没有一种简单的方法来将海报显示给特定的视频元素?
I want to add a poster
tag on a specific video element where the src
of that specific video leads to a 404
error.
To further explain:
I got a list of videos queried from the database, some may lead to 404
error meaning the video files was not uploaded properly, my goal is to add a poster
tag to these videos so I can tell the diffrence from the ones that work properly to the ones that don't
Getting the videos from the database
<?
$storage = new ObjectStorage;
$db->query("SELECT videoId, videoVsId, videoFile, videoUploadTime FROM videos WHERE vidOjId='$jbId' AND videoArchived = '0000-00-00 00:00:00' AND videoFile LIKE '%/videos/uploaded_videos/items/%'");
$i = 0;
while ($db->next_record()) {
list($videoId, $videoVsId, $videoFile, $vidUploaded) = $db->Record;
$vidname = after("_video_", $videoFile);
$url = "https://website.website.com$videoFile";
if($vidUploaded) {
$vidUploaded = "Uploaded: ".date("H:i d/m/Y", strtotime($vidUploaded));
} else {
$vidUploaded = "Last edited: ".date("H:i d/m/Y", filemtime("../uploaded_videos/".$videoFile));
}
$brokenPoster = "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png";
Then I am checking if the url is broken
if(@file_get_contents($url)){
$brokenPoster = "";
} else {
$brokenPoster;
}
At this point I am not sure how to do this, what I have done so far is the following
?>
<div class="videoDiv_<?= $vidId ?>">
<div class="videosDiv" >
<video id="allVideos" width="320" height="240" controls
poster="<?= $brokenPoster?>"
class="img_<?= $videoId?>" src="<?= $videoFile."?nocache=".rand()?>"
type="video/mp4">
</video>
</div>
</div>
<? $i++; } ?>
Obviously the above will show the poster to all the video elements which are 6 and only 2 of them are not playable dude to a 404.
Is there an easy way to show the poster to a specific video element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎走在正确的轨道上,但如果您想仅在损坏的链接上显示海报,您可以测试
$brokenPoster
是否为空,如下所示:You seem on the right track, but if you want to display a poster only on the broken link you could test if
$brokenPoster
is empty or not, like so: