Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:20:03+00:00 2026-05-27T17:20:03+00:00

I am developing a memory game, in which I want to play background music

  • 0

I am developing a memory game, in which I want to play background music while starting the game.

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

Can anyone say what problem I have? This is my soundclass file:

public class Soundclass {
    private SoundPool soundpool;
    private HashMap<Integer, Integer> 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<Integer, Integer>();
        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);
    }

}

and i used this class for given activitycalss .in oncreate function

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);

            }
        });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:20:04+00:00Added an answer on May 27, 2026 at 5:20 pm

    Soundpool is not meant to be used for background music. It has many limitations such as file size loading and playing time. It’s mainly used for sound effects.
    Use the MediaPlayer class for background music.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm developing a game which contained some view (as memory card game) and i
I´m developing a very memory-consuming app and want to use the largeHeap-Tag, which should
I'm developing a program that would require huge amount of memory, and I want
I am developing a software using C# 2.0 which uses about 200MB of memory
I am developing cocos2d game, which supports multiple languages. I created a font file(.png
Let's say I'm developing a game. I run the following class method thousands of
I am developing an wpf application. which uses most amount of memory from my
i'm new in iPhone app development i'm developing a game in which involves choosing
I am developing an application on Android 2.2 which takes extensive memory and my
I'm currently developing a 2D mobile game, and I want the camera to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.