2013-07-17 112 views
1

我有funcional的代碼只能從網址(如youtube.com/watch?v = ....)播放YouTube視頻。我從這個article使用它。但它不適用於縮短網址(如youtu.be/....)。兩種方法都可行嗎?從網址在asp.net網站播放YouTube視頻

Protected Sub SetVideoForPlay() 
    'YouTube Video URL 
    Dim youtubeUrl As String = "http://www.youtube.com/watch?feature=endscreen&v=gfedwjAOMZI&NR=1" 

    Dim vCode As String = youtubeUrl.Substring(youtubeUrl.LastIndexOf("v=") + 2) 
    If vCode.Contains("&") Then 
     vCode = vCode.Substring(0, vCode.LastIndexOf("&")) 
    End If 

    Dim sHtml As String = "<object width='{0}' height='{1}' data='http://www.youtube.com/v/{2}&autoplay=0' codetype='application/x-shockwave-flash'>" & vbCr & vbLf & " &ltparam name='movie' value='http://   www.youtube.com/v/{2}&autoplay=0'></param></object>" 
    'define frame size 
    Dim sWidth As String = "500px" 
    Dim sHeight As String = "500px" 

    'insert code to the Div 
    divVideo.InnerHtml = [String].Format(sHtml, sWidth, sHeight, vCode) 
End Sub 

回答

1

縮短的網址實際上是第三方重定向到YouTube視頻。因此,我認爲您需要找出縮短鏈接(youtu.be或其他)指向哪個網址,然後使用該網址(youtube.com上的網址)來顯示視頻。