我有功能代码可以仅从 url 播放 youtube 视频(如 youtube.com/watch?v=....)。我从这篇文章中使用它中使用了它。但是它不适用于缩短网址(如 youtu.be/....)。两种方式都可以吗?
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 & " <param 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