How to maintain single instance of MediaPlayer [Android]

后端 未结 3 1073
渐次进展
渐次进展 2021-01-18 21:40

I am using android media player class for playing notification sound in my android Application.

MediaPlayer player = MediaPlayer.create(getApplicationContext         


        
3条回答
  •  我在风中等你
    2021-01-18 22:06

    You should consider the Singleton pattern. Make a class MyPlayer that has a static method getMediaPlayer() that returns the same instance of MediaPlayer each time called.

提交回复
热议问题