Search code examples
androidandroid-activityscreenmp3media-player

How to start a media player object in a activity, and then use that same object and another activity?


Example:

Activity 1: main screen.

player = new media player() player.start() //the sound began

now i have to equalize this same sound in another Activity...

Activity 2: edition screen

the sound keeps playing and want to stop example: player.setVolume(0.0) player.stop()

thank you


Solution

  • Declare player as public static in screen1

    then you can access this media player in screen 2

    like screen1

    :

    public static MediaPlayer player;
    
    player=new MediaPlayer();
    

    ================= ===========

    write your code

    Screen 2 ::-

    if you want to use media player in screen 2 use this code ::-

    screen1.player.start(); screen1.player.stop();