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

  • SEARCH
  • Home
  • 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 7545573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:57:56+00:00 2026-05-30T08:57:56+00:00

I am making a game for android which needs to play a small beep

  • 0

I am making a game for android which needs to play a small beep whenever a user touches a certain object.

To do this I have this simple code to create the media player. beep is a small .ogg file of ~1.5 sec length.

MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.beep);
mp.setVolume(0.5f, 0.5f);

and use it like this

mp.start();

The problem I am having is that my game uses the android canvas, and the thread which draws to the canvas also calls mp.start(). I have discovered that playing the sound is taking quite a lot of time, and it is very varied in how long it takes. Sometimes 1ms, sometimes 15ms. This appears to be causing my game to noticeably lag a little bit, as the android canvas is pretty slow anyway.

I’ve had a look at the logs and I don’t appear to having garbage collection causing the delay. I’m wondering if anyone can give me some advice to reduce this delay

EDIT – I’ve just discovered that MediaPlayer is designed for longer sound files, and SoundPool is better for shorter audio files. However, I load the file into the mediaPlayer only once, so I don’t see how it should make any difference. I will test it out though

  • 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-30T08:57:57+00:00Added an answer on May 30, 2026 at 8:57 am

    sorry for my english

    Use SoundPool instead of MediaPlayer cause MediaPlayer need releasing memory after each call or call method mp.release() after each call of player

    SoundPool tutorial here

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

Sidebar

Related Questions

I'm making this game where I'm trying to pair people. So I have this
I am making a game that needs a crosshair. I have been playing with
I'm making a simple 2d game for the android platform, which works perfectly from
We are in the making of an Android app, a quiz game, which we
I'm making my first Android game which is going to be a 3D arcade-ish
i am making a game using andengine in android, in this game various sprites(eggs)
I'm making a flash game this week, it needs to be compatable with both
I am making a game for my CS class and the sprites I have
We are making a game which will add a level editor feature soon. We
For a 2D game I'm making (for Android) I'm using a component-based system where

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.