suku
suku

Reputation: 10929

How to stop mediaplayer being played in a class when app is minimized/closed?

I have a fragment that calls a class which has a mediaplayer in it. On minimizing or closing the app, the mediaplayer continues to play. If the mediaplayer is part of the activity then I can use onPause and onStop methods in which I can say mediaplayer.release() to stop it. Is there something similar that I can do in a class to stop the mediaplayer?

Upvotes: 2

Views: 438

Answers (1)

Luke Joshua Park
Luke Joshua Park

Reputation: 9805

If you declare the media player as static in the class, you can start and stop it in your activities onPause and onResume methods by referencing it through the class name.

Upvotes: 1

Related Questions