exoplayer and xamarin.android

2021-06-29T21:11:28.737+00:00

I am totally new to xamarin. So, basically what I need help with is just to make a videoplayer which is able to play m3u8 hls stream and also pause it and step back a few seconds. I don't why but this task seemed easy at first but now I am really confused. I encoutered a problem meaning that I can't use PlayerView.setPlayer. VS says there's no such method so I don't know how to make this player work.

Was it changed in the updates? How do I make it happen?

using System;
using Android.App;
using Android.OS;
using Android.Runtime;
using Android.Views;
using AndroidX.AppCompat.App;
using Google.Android.Material.FloatingActionButton;
using Google.Android.Material.Snackbar;
using Com.Google.Android.Exoplayer2;
using Com.Google.Android.Exoplayer2.UI;
using Android.Widget;
using Toolbar = AndroidX.AppCompat.Widget.Toolbar;

 protected override void OnCreate(Bundle savedInstanceState)
        {

            PlayerView playerView;
            ProgressBar progressBar;
            ImageView btFullScreen;


            base.OnCreate(savedInstanceState);
            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
            fab.Click += FabOnClick;

            playerView = FindViewById<PlayerView>(Resource.Id.playerview);

            Android.Net.Uri stream = Android.Net.Uri.Parse("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");

            SimpleExoPlayer player = new SimpleExoPlayer.Builder(this).Build();
            PlayerView.SetPlayer(player);   // here I tried writing it differently but nothing worked.


        }
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2021-06-30T05:35:15.6+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Xamarin.Android uses the C# code language, and its syntax is slightly different from that of Java. To set player for the playerView, try using playerView.Player = player command instead. The PlayerView.Player is both the get and set method for the property.

       playerView = FindViewById<PlayerView>(Resource.Id.playerview);  
         
       SimpleExoPlayer player = new SimpleExoPlayer.Builder(this).Build();  
       playerView.Player = player;  
    

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.