Baseflow / XamarinMediaManager

Cross platform Xamarin plugin to play and control Audio and Video
https://baseflow.com
MIT License
768 stars 305 forks source link

No sound after installing my application from Google Play Console internal testing on my Nokia 7 Plus with Android 10 #855

Closed Hobbit7 closed 1 year ago

Hobbit7 commented 2 years ago

I have no sound when I open my application right after downloading and installing it from Google Play Console internal testing. I use a Nokia 7 Plus phone with Android 10. But when I quit my application and reopen it then the sound works normally. Why is there no sound when I open the application the very first time on my Nokia 7 Plus? I only call CrossMediaManager.Current.Init(this); once in OnCreate located in my Activity1.cs.

` protected override void OnCreate(Bundle bundle) { base.SetTheme(Resource.Style.MainTheme); base.OnCreate(bundle); Xamarin.Forms.Forms.Init(this, bundle); Xamarin.Essentials.Platform.Init(this, bundle); CrossMediaManager.Current.Init(this);

 if (Intent.Extras != null)
 {
     foreach (var key in Intent.Extras.KeySet())
     {
         var value = Intent.Extras.GetString(key);
         Log.Debug(TAG, "Key: {0} Value: {1}", key, value);
     }
 }

 DisplayMetrics displayMetrics = new DisplayMetrics();
 WindowManager.DefaultDisplay.GetRealMetrics(displayMetrics);
 int w1 = displayMetrics.WidthPixels;
 int h1 = displayMetrics.HeightPixels;
 _game = new Game1(w1, h1);
 _game.Run();
}`

In addition, I play my songs like this(in another class):

if (Xamarin.Forms.Device.RuntimePlatform == Xamarin.Forms.Device.Android) { string androidfilename = "file:///android_asset/" + songfilename; await CrossMediaManager.Current.Play(androidfilename); }

I use nuget package Plugin.MediaManager (1.1.0).

Edit: I found out that TimeSpan CurrentPosition = CrossMediaManager.Current.Position; stays always at 00:00:00 when there is no sound. In addition, MediaManager.Player.MediaPlayerState state = CrossMediaManager.Current.State; is always "Stopped", it never changes to "Play". I don't understand why the song is not playing when I call await CrossMediaManager.Current.Play(androidfilename); or await CrossMediaManager.Current.Play("audioUrl");.

Does someone have the same issue on Android? When will this issue be fixed?

Edit: I have tested the same application on 2 other Android devices and the sound works normally right after downloading and installing it from Google Play Console internal testing on the following 2 devices: On a Samsung Galaxy Tab S7 FE the sound works normally on Android 11 and Android 12. On an old Samsung Galaxy Note 10.1 2014 Edition the sound works normally on Android 5.1.1.

I only have the sound problem on my Nokia 7 Plus phone with Android 10.

gsgou commented 2 years ago

I have the same issue with Redmi Note 10 Pro - Android 12 and i also do not see any logs.

gsgou commented 2 years ago

Could relate on this one: https://github.com/google/ExoPlayer/issues/10162 @Hobbit7 did you find any workaround?

gsgou commented 2 years ago

fixed it by explicitly setting Speed to 1f before playback

Hobbit7 commented 2 years ago

fixed it by explicitly setting Speed to 1f before playback

Could you give me a code example? How have you changed the setting Speed to 1f? Is it necessary to change it each time to 1f before you use await CrossMediaManager.Current.Play(androidfilename); to play a song?

gsgou commented 2 years ago

I dont know if its always required. By setting it always before Play() it works now in a Redmi Note 10 Pro - Android 12 where i could reproduce the issue. I do not set it before calling PlayPause(). There seems not to be necessary.