Dependency service and mediaPlayer
10:21 31 Aug 2020

i am using dependency service to use Android MediaPlayer, however once i return the value from media player to shared project the value mediaplayer is null. I have seen and tried https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/MediaElementDemos/MediaElementDemos.Android/VideoPicker.cs

My interface

public interface IDictionaryPlayer
   {
        MediaPlayer SetGong(int timeoutBetweenWords);
  
   }

Droid

  public MediaPlayer SetGong(int timeout)
     {
                MediaPlayer pausesPlayer = MediaPlayer.Create(Android.App.Application.Context, Resource.Raw.gong);
    
                return pausesPlayer;
                
    }

Shared project

    public static MediaPlayer GongPlayer;
    
         public static void SetPauseOrGongBetweenWords(int timeoutBetweenWords)
         {
                            GongPlayer = DependencyService.Get().SetGong(timeoutBetweenWords); // HERE ITS NULL
                            initialize = true;
       GongPlayer.Start();
         }

 public static void TryPausePlayer()
        {
            lock (playerLock)
            {
               
                if (GongPlayer != null && GongPlayer.IsPlaying)
                {
                    gongNeedsResume = true;
                    GongPlayer?.Pause();
                }
            }
        }
  public static void TryResumePlayer()
        {
           if (gongNeedsResume)
            {
                    gongNeedsResume = false;
                    GongPlayer?.Start();
            }
            
        }

 internal static void Clean()
        {
            disposeActive = true;

            if (GongPlayer != null)
            {
                GongPlayer.Dispose();
                GongPlayer = null;
            }
        }
xamarin.forms media-player