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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:45:04+00:00 2026-05-18T10:45:04+00:00

Scenario I have a problem that starts to drive me nuts. In one activity

  • 0

Scenario

I have a problem that starts to drive me nuts. In one activity I have the following scenario. On create:
– create a GPS Listner
– create a Location Listener
– Start GPS listner and location listener
– Start a asyncTask that downloads a map from the web / or load it from cache
– play a wav file which is a raw resource, very small (around 63 Kilo) which is short, basically it says: “Let’s head to the start point” and it makes visible a textview for 10 seconds.

Problem

Rarely the sound gets play fully. Sometimes I hear only “Let’s head”, sometimes “Let’s head to the star”, sometimes no play at all. It’s like something else is blocking the sound. I moved the sound in its own thread but still no success:

Code

private void ShowTextPlayVoice(String message, int soundResId)
    {
        txtProceed.setText(message);
        txtProceed.setVisibility(View.VISIBLE);
        final int soundId = soundResId;

        Handler splashHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                    switch (msg.what) {
                    case 0:
                            txtProceed.setVisibility(View.INVISIBLE);
                            break;
                    }
                    super.handleMessage(msg);
            }
        };

            Message msg = new Message();
            msg.what = 0;
            splashHandler.sendMessageDelayed(msg, 10000);

            Thread thread = new Thread() {
                public void run() {
                    MediaPlayer mp = MediaPlayer.create(ctx, soundId);
                    mp.start();
                    mp.setOnCompletionListener(new OnCompletionListener() {
                                    public void onCompletion(MediaPlayer mp) {
                                        mp.release();
                                    }
                                });
                }
            };
            thread.start();
    }

Thank you all for help.

  • 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-18T10:45:04+00:00Added an answer on May 18, 2026 at 10:45 am

    After some tries, here is a working solution

    private MediaPlayer mediaPlayer = new MediaPlayer();
    
    private void ShowTextPlayVoice(String message, int soundResId)
        {
            txtProceed.setText(message);
            txtProceed.setVisibility(View.VISIBLE);
    
            Handler splashHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                        switch (msg.what) {
                        case 0:
                                txtProceed.setVisibility(View.INVISIBLE);
                                break;
                        }
                        super.handleMessage(msg);
                }
            };
    
                Message msg = new Message();
                msg.what = 0;
                splashHandler.sendMessageDelayed(msg, 10000);
    
               new SoundTask().execute(soundResId);
        }
    
        protected class SoundTask extends AsyncTask<Integer, Void, Void>
        {
            @Override
            protected Void doInBackground(Integer... params) 
            {
                AssetFileDescriptor afd = ctx.getResources().openRawResourceFd(params[0]);
    
                try
                {   
                    //final MediaPlayer mediaPlayer = new MediaPlayer();
                    mediaPlayer.reset();
                    mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
                    mediaPlayer.prepare();
                    mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
                        public void onPrepared(MediaPlayer arg0) {
                             mediaPlayer.seekTo(0);
                             mediaPlayer.start();
                                                    });
                        }
                    });
                    afd.close();
                }
                catch (Exception e) {
                }
    
                return null;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, Here is my scenario: I have two activity and one service --> all
I have the following scenario jQuery('#content').fadeOut('slow',function(){ jQuery('#content').load(detail.php?product=+imgID+&category=+cat); jQuery('#content').fadeIn('fast'); }); My problem however is that
I have a problem regarding getting the path of a user control. The scenario
I have some problems with my DAO implementation. My scenario: I insert one entity
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario I have two wrappers around Microsoft Office, one for 2003 and one for
Scenario: I have a console application that needs to access a network share with
I am facing a situation that I have problem understanding... I am writing a
The scenario is that I arrive at work one morning and pull, update, merge

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.