'How to play video using ypoutube or any other url in xamarin forms
i want to play video from youtube link or other video url. but video is not play
<xct:MediaElement x:Name="mediaElement"Grid.Row="0" HeightRequest="300"
ShowsPlaybackControls="True" Source="https://www.youtube.com/watch?v=FPeGkedZykA"/>
Solution 1:[1]
To be clear, the youtube url link is a web-based video player, not a direct video link.There are 2 ways that you can play youtube url in Xamarin forms.
1.Use YoutubeExplode plugin.
<xct:MediaElement x:Name="MyMediaElement" WidthRequest="200"
HeightRequest="200" ShowsPlaybackControls="True" />
The in your page.cs
public MainPage()
{
InitializeComponent();
GetVideoContent();
}
private async void GetVideoContent()
{
var youtube = new YoutubeClient();
// You can specify video ID or URL
var video = await youtube.Videos.GetAsync("https://www.youtube.com/watch?v=FPeGkedZykA");
var title = video.Title; // "Downloaded Video Title"
var author = video.Author; // "Downloaded Video Author"
var duration = video.Duration; // "Downloaded Video Duration Count"
//Now it's time to get stream :
var streamManifest = await youtube.Videos.Streams.GetManifestAsync("https://www.youtube.com/watch?v=FPeGkedZykA");
var streamInfo = streamManifest.GetMuxedStreams().GetWithHighestVideoQuality();
if (streamInfo != null)
{
// Get the actual stream
var stream = await youtube.Videos.Streams.GetAsync(streamInfo);
MyMediaElement.Source = streamInfo.Url;
}
}
2.Use webview
<WebView x:Name="myurl" VerticalOptions="FillAndExpand" HeightRequest="600"></WebView>
Then set url in page.cs.
myurl.Source = "https://www.youtube.com/watch?v=FPeGkedZykA";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alexandar May - MSFT |

