2013-04-17 61 views
3

我想開發一個應用程序,並在ListView中顯示YouTube視頻。 像原始的YouTube應用程序,但沒有視頻加載。只有一個顯示視頻的ListView,只需點擊一下,就可以進入加載視頻的YouTube-App。來自YouTube的預覽視頻

但是我如何在我的應用程序中顯示視頻預覽?是否有我可以使用的API或其他技巧? 我的第一個想法是,我從每個視頻都做了一個圖片......但是..是啊! :)

下面是一個例子形象 enter image description here

回答

5

你可以做一個HTTP POST到這個地址:

http://www.youtube.com/oembed?url={complete youtube url}&format=json 

其中{完成YouTube網址}是視頻的完整URL。

例如:

http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=AJ0sW7KOFhU&format=json 

應該回答你這個JSON:

{ 
author_url: "http://www.youtube.com/user/neiljohnson666", 
version: "1.0", 
provider_name: "YouTube", 
provider_url: "http://www.youtube.com/", 
thumbnail_url: "http://i2.ytimg.com/vi/AJ0sW7KOFhU/hqdefault.jpg", 
author_name: "Neil Johnson", 
type: "video", 
width: 480, 
height: 270, 
title: "Manowar - Warriors of the World HD", 
thumbnail_width: 480, 
html: "<iframe width="480" height="270" src="http://www.youtube.com/embed/AJ0sW7KOFhU?  feature=oembed" frameborder="0" allowfullscreen></iframe>", 
thumbnail_height: 360 
} 

所以thumbnail_url是你正在尋找的形象:

that thumbnail_url

希望幫助,歡呼!

+0

謝謝。這有一點幫助。它很酷是的。我還可以獲得時間視頻是多久? – StefMa

+1

當然,試試這個:http://gdata.youtube.com/feeds/api/videos/AJ0sW7KOFhU?v=2&alt=jsonc其中AJ0sW7KOFhU是YouTube視頻ID,有一個視頻持續時間字段 –

+0

謝謝。好幫手! – StefMa