I will discuss how to integrate youtube video in asp.net. Youtube provides the API to access the its huge database of videos. It also provides search facility and customized player for integration.
First thing you need is to get developer key for accessing youtube service. You can get it from here. Once you get the developer you can use the API URL to retrieve youtube videos. The URL is,
Fig – (1) Youtube API URL
There specific parameters that you need to pass in query string to get desire result from youtube. See the list below,
Fig – (2) Parameters for youtube querystring
So from fig – (1) and (2) if you need to search video for asp.net and you need 10 records per page and page should display 3rd page the the URL will be,
Fig – (3) Querystring for youtube video
Use page=-1 and per_page=-1 to display all the videos on same page without paging. You will get reply in XML format from this URL. You can retrieve that XML as XML document and use XQuery to to get the desire result. OR you can generate dataset from that XML using ReadXML method. I have used ReadXML method.
This will create three tables (1) ut_response , (2) video_list and (3) video. in dataset. ut_response table contains the information whether the supplied DeveloperId is correct? If yes, the status field contains “ok”. video_list contains total number of videos returned. video table contains the information about the videos.
Fig – (4) Function to retrieve youtube video in ASP.NET
You can retrieve youtube videos using above function in ASP.NET. Youtube also provides player integration details.
Lets have a look at the code below. This code displays all youtube videos played in same asp.net page.
Fig – (5) Youtube asp.net aspx page.
Fig – (6) Youtube asp.net aspx.cs page.
Happy Programming !!!