0

the video is playing normally, but if you open another application and go back, vlc will show a black screen with a only sound. (Android 8.0.0, last version of nuget package)

LibVLC libVLC = new LibVLC("--preferred-resolution=-1", " --log-verbose=3", "--no-gnutls-system-trust");
MediaPlayer mediaPlayer;
Media media = new Media(libVLC, playerUrl, FromType.FromLocation);
VideoView1.MediaPlayer = mediaPlayer;
mediaPlayer.Play();
Bkkkkkk90
  • 3
  • 1
  • When you go back to your app, does that same code execute again? If so, you've started a second mediaplayer, but did not tell the first one to stop. The first one (which you are no longer seeing) still has the video. I'm not familiar with mediaplayer, but the basic concept is that in your Xamarin.Android project's app's (or maybe mainactivity's) OnPause you need to "clean up" active resources (stop the video, maybe Dispose also), then save info (maybe in a Bundle) to tell your app what "state" it was in. if you want to get back to the same location in video in OnCreate or OnResume. – ToolmakerSteve Nov 06 '21 at 19:05
  • @ToolmakerSteve, No, the media player is created once when you click on the element. Yes, creating a new media player might help, but it's a very bad idea.. thank you for your response – Bkkkkkk90 Nov 06 '21 at 19:57
  • I was not suggesting that you create a new media player. Rather, I was *asking* if you breakpoint your code, *does that code get executed again* when it returns to the app. (If it did, then that would create a new player, so you'd need to do something like what I suggested.) Good if it does not. Anyway, the symptom suggests that leaving the app and returning to it results in media player being in a bad state. The fix must involve "doing something" when your app goes into background, then "doing something else" when it resumes. – ToolmakerSteve Nov 06 '21 at 20:48
  • Probably because the "surface" changes when app resumes. Maybe investigate discussions at the android level, such as https://stackoverflow.com/q/6347924/199364. – ToolmakerSteve Nov 06 '21 at 20:55
  • Yes, it looks like I'll have to create a new mediaplayer, and a new videoview. Unfortunately... – Bkkkkkk90 Nov 06 '21 at 20:55
  • 1
    One person claims to have it working for the android mediaplayer. Don't know if this applies to vlc: https://stackoverflow.com/a/34854913/199364 – ToolmakerSteve Nov 06 '21 at 21:03

1 Answers1

0

On Android, background support needs a bit of ceremony due to how the OS works. Simply, it means you need to recreate a VideoView and set your existing MediaPlayer on it to have video working when coming back from the background.

Sample demonstrating this is available https://code.videolan.org/mfkl/libvlcsharp-samples/-/tree/master/ForegroundBackground

mfkl
  • 1,914
  • 1
  • 11
  • 21