Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: How to stop this music already?
    primarykey
    data
    text
    <p>I have created an application and with some background music.</p> <p>Result = SUCCESS</p> <p>Problem is.. -.- if app receives a call, music is still playing and plays instead of the user's original ringtone. Plus if "Home" button is selected on the phone. Activity exits but the music is still running?</p> <p>I managed to quit the music if the "Back" button on the phone is selected.</p> <p>other than that music runs 24/7.</p> <p>What I have used is.</p> <p>A menu option in the application that when the user selected "Menu" a list of options pop up and an option to choose "Settings..." If the user selects "Settings..." a preference dialogue pops up to check or uncheck music (ON/OFF) Result = SUCCESS</p> <p>The music plays throughout the application, from activity to activity.</p> <p>This is my media player code in my application.</p> <pre><code>@Override protected void onPause() { super.onPause(); } @Override protected void onResume() { super.onResume(); Music.play(this, R.raw.bgmusic); } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(true); finish(); Music.stop(this); return true; } return super.onKeyDown(keyCode, event); } </code></pre> <p>This is my music.java</p> <pre><code>public class Music { private static MediaPlayer mp = null; /** Stop old song and start new one */ public static void play(Context context, int resource) { stop(context); // Start music only if not disabled in preferences if (Prefs.getMusic(context)) { mp = MediaPlayer.create(context, resource); mp.setLooping(true); mp.start(); } } /** Stop the music */ public static void stop(Context context) { if (mp != null) { mp.stop(); mp.pause(); mp.release(); mp = null; } } } </code></pre> <p>anyone have a clue?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload