如何将海报添加到多个视频列表中的特定视频元素

发布于 2025-01-11 06:03:53 字数 1850 浏览 0 评论 0原文

我想在特定视频元素上添加 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜声 2025-01-18 06:03:53

您似乎走在正确的轨道上,但如果您想在损坏的链接上显示海报,您可以测试 $brokenPoster 是否为空,如下所示:

<div class="videoDiv_<?= $vidId ?>">
            
    <div class="videosDiv" >
        <video id="allVideos" width="320" height="240" controls 
         <?php if (!empty($brokenPoster) { echo 'poster="'.$brokenPoster.'"'; } ?>
         class="img_<?= $videoId?>" src="<?= $videoFile."?nocache=".rand()?>"
             type="video/mp4">
        </video>    
    </div>
    
</div>

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:

<div class="videoDiv_<?= $vidId ?>">
            
    <div class="videosDiv" >
        <video id="allVideos" width="320" height="240" controls 
         <?php if (!empty($brokenPoster) { echo 'poster="'.$brokenPoster.'"'; } ?>
         class="img_<?= $videoId?>" src="<?= $videoFile."?nocache=".rand()?>"
             type="video/mp4">
        </video>    
    </div>
    
</div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文