Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Play Video

$
0
0

Hi, Im trying to play a video from xamarin forms through MessagingCenter. In iOS I use:

`private void HandleShowVideoPlayerMessage(Page page, ShowVideoPlayerArguments arguments)
{
var presentingViewController = GetMostPresentedViewController();
var filename = arguments.Url;

        var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        var filename2 = Path.Combine(documents, filename);

        var url = new NSUrl(filename2, false);


        var avp = new AVPlayer(url);
        var avpvc = new AVPlayerViewController();
        avpvc.Player = avp;
        avp.Play();

        presentingViewController.PresentViewController(avpvc, animated: true, completionHandler: null);
    }

    private UIViewController GetMostPresentedViewController()
    {
        var viewController = UIApplication.SharedApplication.KeyWindow.RootViewController;

        while (viewController.PresentedViewController != null)
        {
            viewController = viewController.PresentedViewController;
        }

        return viewController;
    }`

But on Android I can't seem to make it work.
Im trying this:
`
private void HandleShowVideoPlayerMessage(Page page, ShowVideoPlayerArguments arguments)
{
VideoView videoView = FindViewById(Resource.Id.SampleVideoView);

        var uri = Android.Net.Uri.Parse("https://www.youtube.com/watch?v=pR30knJs4Xk");
        videoView.SetMediaController(new MediaController(this));
        videoView.SetVideoURI(uri);
        videoView.RequestFocus();
        videoView.Start();
    }

`
But it trows an exception.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>