question

35153060 avatar image
0 Votes"
35153060 asked RobCaplan edited

exoplayer and xamarin.android

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.
    
     
         }

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JarvanZhang-MSFT avatar image
1 Vote"
JarvanZhang-MSFT answered JarvanZhang-MSFT commented

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.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot! It really helped! Is there a website or a manual where I could learn all of this exoplayer methods on Xamarin? I mostly try to adapt the code from Java but sometimes I end up in dead ends.

0 Votes 0 ·

@35153060 To get what method the class provides, you could place the cursor of the mouse on the class and press F12 to check the source code.

0 Votes 0 ·

yeah, I know about F12 but the thing is that there is a very limit list of things and I still don't understand how to call certain methods. For example, on the website of Exoplayer developer there's this:


 // Create a player instance.
 SimpleExoPlayer player = new SimpleExoPlayer.Builder(context).build();
 // Set the media item to be played.
 player.setMediaItem(MediaItem.fromUri(hlsUri));
 // Prepare the player.
 player.prepare();

But I couldn't find anything about setMediaItem when I pressed F12.

0 Votes 0 ·
Show more comments