Har*_*hah 2 asp.net xamarin.ios xamarin.android xamarin xamarin.forms
我正在实现 xamarin 表单媒体元素。我可以从 xamarin 媒体元素官方文档中提供的链接播放视频。但问题是我想播放 youtube 视频,但它没有播放。我已经在 app.xaml.cs 中设置了标志,但 YouTube 视频仍然没有任何反应。它仅在模拟器和物理设备中显示空白屏幕。
<MediaElement Source="https://youtu.be/E7Voso411Vs" x:Name="mediaSource"
AutoPlay="True" ShowsPlaybackControls="True"
VerticalOptions="FillAndExpand" />
Run Code Online (Sandbox Code Playgroud)
希望得到解决。
谢谢你。
You should extract url from youtube with https://www.youtube.com/get_video_info?video_id={VideoId}
first,try this:
<MediaElement x:Name="mediaSource"
AutoPlay="True" ShowsPlaybackControls="True"
VerticalOptions="FillAndExpand" />
Run Code Online (Sandbox Code Playgroud)
then in your page.cs:
public MediaElem()
{
InitializeComponent();
mediaSource.Source = GetYouTubeUrl("E7Voso411Vs");
}
public string GetYouTubeUrl(string videoId)
{
var videoInfoUrl = $"https://www.youtube.com/get_video_info?video_id={videoId}";
using (var client = new HttpClient())
{
var videoPageContent = client.GetStringAsync(videoInfoUrl).Result;
var videoParameters = HttpUtility.ParseQueryString(videoPageContent);
var encodedStreamsDelimited1 = WebUtility.HtmlDecode(videoParameters["player_response"]);
JObject jObject = JObject.Parse(encodedStreamsDelimited1);
string url = (string)jObject["streamingData"]["formats"][0]["url"];
return url;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1479 次 |
最近记录: |