【问题标题】:Image cannot be loaded. Make sure the path is correct and the image exists无法加载图像。确保路径正确且图片存在
【发布时间】:2012-07-20 21:51:42
【问题描述】:

在我的页面上,我有一个 YouTube 视频的缩略图作为图片,我想在用户点击图片后使用 prettyPhoto 播放视频。我怎样才能做到这一点?

这是我的图片代码:

<div class="video" id="videoPlaceHolder" style="position:relative;">
  <a rel="prettyPhotos" href="https://www.youtube.com/embed/<?php getFirstFeatureVideoURL(); ?>">
    <img style="background:url(<?php getFirstFeatureVideoThumbnail() ?>); background-repeat:no-repeat; background-size:cover;  -moz-background-size: cover;" src="/images/ytIndex_overlay.png" onClick="addPlayer();" />
  </a>
</div>

php 函数getFirstFeatureVideoURL 抓取并返回第一个视频的“正确”URL(我已经单独检查过,视频播放没有任何问题)。另一个名为getFirstFeatureVideoThumbnail 的函数返回视频的缩略图。我已经为prettyPhoto 准备好了所有插件,到目前为止,它可以完美地处理所有图像。但是,当我尝试通过单击图像来播放此视频时,它给了我错误:

Image cannot be loaded. Make sure the path is correct and the image exists

为什么会出现这个错误?

【问题讨论】:

    标签: video youtube xhtml-1.0-strict prettyphoto


    【解决方案1】:

    它期望 href 是一个 URL。你不能在这样的 URL 中嵌入 PHP 代码。

    【讨论】:

    【解决方案2】:

    您要获取的缩略图版本是什么。我猜您尝试检索标准清晰度缩略图或最大分辨率缩略图。对于此视频 id,它们都不存在:Id_kGL3M5Cg

    使用此工具检查它是否存在:YouTube video info generator

    我得到了结果, 标准清晰度缩略图不适用于此视频。 此视频不提供最大分辨率缩略图。

    您可以使用get_headers 检查图像是否存在。查看本教程中代码的缩略图部分:How to get YouTube Video Info with PHP

    【讨论】:

      【解决方案3】:

      好的,所以我最终在我的 PHP 函数中生成了 和 标记,如下所示,这解决了我的问题....

      function getFeatureVideo()
      {
      $xml = simplexml_load_file('https://gdata.youtube.com/feeds/api/playlists/A4F160EDF82713A2?v=2');
      .
      .
      .
      .
      $media = $entry->children('http://search.yahoo.com/mrss/');
      
        $attrs = $media->group->player->attributes();
        $watch = $attrs['url'];
      
        $attrs = $media->group->thumbnail[1]->attributes();
        $thumbnail = $attrs['url'];
      
        $result .='<a rel="prettyVideos"  href="'.$watch.'">
                      <img style="background:url('.$thumbnail.'); background-repeat:no-repeat; background-size:cover;  -moz-background-size: cover;" src="/images/ytIndex_overlay.png" onClick="addPlayer();" />
             </a> ';      
      
      echo $result;                    
      }
      

      【讨论】:

        猜你喜欢
        • 2014-01-09
        • 1970-01-01
        • 2014-12-17
        • 2018-03-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-06
        • 2021-10-24
        相关资源
        最近更新 更多