gpt4 book ai didi

c# - 从URL在asp.net网站上播放youtube视频

转载 作者:行者123 更新时间:2023-12-03 05:42:08 25 4
gpt4 key购买 nike

我有功能代码,只能从网址播放youtube视频(例如youtube.com/watch?v = ....)。我从article中使用了它。但是,它不适用于较短的网址(例如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 & " &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

最佳答案

缩短的URL实际上是第三方重定向到YouTube视频。因此,我认为您需要找出缩短的链接(youtu.be或其他)指向哪个URL,然后使用该URL(youtube.com上的那个)显示视频。

关于c# - 从URL在asp.net网站上播放youtube视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com