Playing background music during entire game
<p>I am developing a memory game, in which I want to play background music while starting the game.</p>

<p>I used sound pool class and successfully executed it, but I have problem in playing. I added <code>.mp3</code> audio file of two minutes, but it's playing only for 15 seconds more.</p>

<p>Can anyone say what problem I have? This is my soundclass file:</p>

<pre><code>public class Soundclass {
    private SoundPool soundpool;
    private HashMap&lt;Integer, Integer&gt; soundpoolmap;
    private AudioManager audiomanager;
    private Context context;

    public void initSounds(Context thecontext) {
        context = thecontext;
        soundpool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
        soundpoolmap = new HashMap&lt;Integer, Integer&gt;();
        audiomanager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
    }

    public Soundclass() {

    }

    public void addSound(int Index, int soundID) {
        soundpoolmap.put(Index, soundpool.load(context, soundID, 1));
    }

    public void playSound(int Index) {
        float streamVolume = audiomanager
                .getStreamVolume(AudioManager.STREAM_MUSIC);
        streamVolume = streamVolume
                / audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        soundpool.play(soundpoolmap.get(Index), streamVolume, streamVolume, 1,
                0, 1f);
    }

    public void playLoopedSound(int Index) {
        float streamVolume = audiomanager
                .getStreamVolume(AudioManager.STREAM_MUSIC);
        streamVolume = streamVolume
                / audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
        soundpool.play(soundpoolmap.get(Index), streamVolume, streamVolume, 1,
                -1, 1f);
    }

}
</code></pre>

<p>and i used this class for given activitycalss .in oncreate function</p>

<pre><code>Button btn = (Button) findViewById(R.id.sound);
        soundclass = new Soundclass();

        soundclass.initSounds(getBaseContext());
        soundclass.addSound(1, R.raw.jinglebells);

        btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                soundclass.playSound(1);

            }
        });
</code></pre>
