Wednesday, 16 November 2016

Getting Youtube Video Thumbnail image

<!--  This is for sample test code  -->

  <script type="text/javascript"> function getScreen( url, size ) {
if(url === null){
return "";
}
size = (size === null) ? "big" : size;
var vid;
var results;

results = url.match("[\\?&]v=([^&#]*)");
vid = ( results === null ) ? url : results[1];
if(size == "small"){
return "http://img.youtube.com/vi/"+vid+"/2.jpg"; }
else {
return "http://img.youtube.com/vi/"+vid+"/0.jpg"; }
}
</script>

 <%
  String url = "http://www.youtube.com/watch?v=E88uMNtPjvw";
 %>
<script type="text/javascript">

var imgUrl_small = getScreen("<%=url%>",'small');

 alert("this is image Url :"+imgUrl_small);

document.write('<img src="' + imgUrl_big + '" />');
document.write('<img src="' + imgUrl_small + '" />');

</script>

I hope its usefully for you..

No comments:

Post a Comment