View a Youtube video via videoView via Xamarin

Asked

Viewed 651 times

0

I need to show a video for a URL, such as a youtube link, using the tool Videoview, or similar.

I did some research on this, and I got this code, but it didn’t work, I always get the message that I could not run the video.

I already gave permission and checked the internet connection and everything is ok, I tested the APP both in emulator, and mobile.

If anyone can help me with this I’d be very grateful!

My code:

public void playVideo()
            {
                try
                {
                    string url = "https://www.youtube.com/watch?v=2lkBFpyo1Mc";
                    nvidCamera.SetVideoURI(Android.Net.Uri.Parse(url));
                    nvidCamera.RequestFocus();
                    nvidCamera.Start();
                }
                catch (Exception ex)
                {
                    alertShow("Ocorreu um problema: " + ex, false);
                }
            }

1 answer

1


There is no way, youtube provides the API itself, they will never provide the real URL of the Youtube video, so why would it violate various legal concepts, as well as the right of owners, out who still has the videos of advertisements that are their way to earn money through this service which is free to us.

Here is the download of Youtube API: https://developers.google.com/youtube/android/player/downloads/

And some examples on github/youtube ready: https://github.com/youtube/api-samples

However I don’t know how to use this in Xamarim, so an alternative solution would be to use a webView + youtube embedded url, something like:

var youtubePlayer = new WebView {
      Source = "https://www.youtube.com/embed/ID_VIDEO"
};

More details on https://developer.xamarin.com/guides/xamarin-forms/user-interface/webview/

Please if you have any questions regarding this comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.