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 4082162
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:09:11+00:00 2026-05-20T18:09:11+00:00

Ok well I have been fighting with this for a while now and have

  • 0

Ok well I have been fighting with this for a while now and have soundboard apps that I havn’t ran into this problem in. I am developing a widget that allows for a sound to be played when a button is pressed on the widget.

I am assuming I am just not using the setOnPreparedListener properly but basically what is happening is that some of my sounds play correctly and more likely than not the sounds will cut off the last part noticeable by word or sound effect missing. Below is my code please let me know if you have any idea what’s wrong with the code or post a working revision.

Thanx in advance.

    public int onStartCommand(Intent intent, int flags, int startId) {

            /** Get our place holder for quotes & sounds. */
            int s = UpdateService.getQuoteNumber();

            /** Check if a sound is playing if so... stop and reset it. */
            if (mp != null && mp.isPlaying()){mp.stop();mp.reset();}

            /** Create a new mediaplayer and set looping. */
            mp = MediaPlayer.create(this, SoundsClicked.randomSound[s]);
            mp.setLooping(false);

            /** Try to prepare the sound/mediaplayer, if not report error & type. */
            try {mp.prepare();} 
                catch (IllegalStateException e) {e.printStackTrace();Log.e(Integer.toString(s), "IllegalStateException");} 
                catch (IOException e) {e.printStackTrace();Log.e(Integer.toString(s), "IOException");}              

            /** Check if the sound is prepared, if so play it. */
            mp.setOnPreparedListener(new OnPreparedListener() {
                public void onPrepared(MediaPlayer mp) {
                    mp.start();
                    while (mp.isPlaying()) {};
                }
            });
            return flags;}

This is called from a service (obviously from the onStartCommand) but figured I would throw that out there for those not familiar with some of the methods.

  • 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-20T18:09:12+00:00Added an answer on May 20, 2026 at 6:09 pm

    If you’re using Android 2.2, there are apparently some problems with the MediaPlayer cutting off the last X% of at least some audio files. I’m running in to that problem with the app I’m currently working on. I haven’t found if there is a solution or not.

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

Sidebar

Related Questions

Well I have this MySQL stored procedure that I wrote and if I run
Well basically I have this script that takes a long time to execute and
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I've been fighting with this problem all day and am just about at my
I have been working on this a while. I see multi-dimensional arrays in php
Object-relational mapping has been well discussed, including on here. I have experience with a
well i have this messages table with sample values like these: msg_id recipient_id read
I have two tables (well, two relevant for this question) : Bets (holds the
We have an application (well, 3) which uses Oracle 9i, however this is being
I have an application that works pretty well in Ubuntu, Windows and the Xandros

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.