无法加载图片。确保路径正确且图像存在

时间:2012-07-20 21:51:42

标签: video youtube xhtml-1.0-strict prettyphoto

在我的页面上,我有一个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

为什么我收到此错误?

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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

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

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

答案 2 :(得分:-1)

好的,所以我最终生成了&lt; a&gt;和&lt; img&gt;我的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;                    
}