I have a WordPress site in which I am inserting video embed code in the post editor. In the front end I need to show the video Thumbnail on click on them it will show the video in lightbox.
The requirement is that, I need to show the video thumbnail of the videos I have given in the editor.
I will use YouTube and vimeo embed code and if it is other video then I will show post thumbnail, or a default image.
I will use one video embed code per posts.
Thanks in advance.
Using Youtube API
http://img.youtube.com/vi/VIDEO_ID/#.jpg
where,
VIDEO_ID = bQVoAWSP7k4
# = 1,2, or 3
Using Vimeo API
Making Video Request
http://vimeo.com/api/v2/video/video_id.output
where,
video_id : The ID of the video you want information for.
output : Specify the output type. It currently offer JSON, PHP, and XML formats.
php code for vimeo:
$imgid = 6825415;
$image = unserialize(file_get_contents("http://vimeo.com/api/v2/video/$imgid.php"));
echo $image[0]['thumbnail_medium'];
Thumbnails you can load from video url.
VIDEO URL
http://www.youtube.com/watch?v=Xzf0rvQa4Mc
THUMBNAIL URL
http://i1.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i2.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i3.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
http://i4.ytimg.com/vi/Xzf0rvQa4Mc/default.jpg
It takes some time to replicate images to all thumbnails urls (maybe servers) for new videos.
If there is no thumbnail, it returns image with camera (exactly 893 bytes length).
EXAMPLE
http://i4.ytimg.com/vi/Xzf0rvQa4Md/default.jpg
if you want to get yout tube video id like this
better with this
regexp (youtube\.com\/(watch\?v=)?(v\/)?([\w\-]+))
it can handle both urls (with /v/ and with watch?v=)
preg_match('/youtube\.com\/v\/([\w\-]+)/', $code, $match);
echo $match[3];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With