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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:16:59+00:00 2026-06-18T08:16:59+00:00

I am implementing an application which used to play an audio file (output from

  • 0

I am implementing an application which used to play an audio file (output from Text to speech and stored in mnt/sdcard/audiofiles/audio.mp3). When I try to play this using MediaPlayer I get an error.

Code:

MediaPlayer  mMediaPlayer = new MediaPlayer();
try {
  mMediaPlayer.setDataSource("/mnt/sdcard/audiofiles/audio01.mp3");
  mMediaPlayer.prepare();
} catch (IllegalArgumentException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
} catch (IllegalStateException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}
mMediaPlayer.start();

Error:

  02-05 13:11:40.859: I/SynthProxy(286): setting pitch to 100<br>
  02-05 13:11:40.898: E/MediaPlayer(15651): error (1, -2147483648)<br>
  02-05 13:11:40.898: W/System.err(15651): java.io.IOException: Prepare failed.: status=0x1<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.media.MediaPlayer.prepare(Native Method)<br>
  02-05 13:11:40.898: W/System.err(15651):  at com.example.testmedai1.MainActivity$MySpeech.onInit(MainActivity.java:93)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.speech.tts.TextToSpeech$1.onServiceConnected(TextToSpeech.java:451)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.app.ActivityThread$PackageInfo$ServiceDispatcher.doConnected(ActivityThread.java:1247)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.app.ActivityThread$PackageInfo$ServiceDispatcher$RunConnection.run(ActivityThread.java:1264)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.os.Handler.handleCallback(Handler.java:587)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.os.Handler.dispatchMessage(Handler.java:92)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.os.Looper.loop(Looper.java:123)<br>
  02-05 13:11:40.898: W/System.err(15651):  at android.app.ActivityThread.main(ActivityThread.java:4627)<br>
  02-05 13:11:40.898: W/System.err(15651):  at java.lang.reflect.Method.invokeNative(Native Method)<br>
  02-05 13:11:40.898: W/System.err(15651):  at java.lang.reflect.Method.invoke(Method.java:521)<br>
  02-05 13:11:40.898: W/System.err(15651):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)<br>
  02-05 13:11:40.898: W/System.err(15651):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)<br>
  02-05 13:11:40.898: W/System.err(15651):  at dalvik.system.NativeStart.main(Native Method)<br>
  02-05 13:11:40.898: E/MediaPlayer(15651): start called in state 0<br>
  02-05 13:11:40.898: E/MediaPlayer(15651): error (-38, 0)<br>
  02-05 13:11:40.918: E/MediaPlayer(15651): Error (-38,0)<br>                                        

Edit 1:

This is the total code I am trying, When button1 clicked I creating an audio file. I checked for the file using DDMS->File Exploring and saved it to my desktop and played. It is working fine. But when I try to access it pragmatically and try to play I got the error.

 package com.example.testmedai1;

 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.HashMap;


 import android.media.MediaPlayer;
 import android.os.Bundle;
 import android.os.Environment;
 import android.app.Activity;
 import android.speech.tts.TextToSpeech;
 import android.speech.tts.TextToSpeech.OnInitListener;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.Toast;

 public class MainActivity extends Activity {

Button store, play;
EditText input;
String speakTextTxt;
TextToSpeech mTts;
private String path;
HashMap<String, String> myHashRender = new HashMap<String, String>();
String tempDestFile ;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    store = (Button) findViewById(R.id.button1);
    play = (Button) findViewById(R.id.button2);
    input = (EditText) findViewById(R.id.editText1);
    store.setOnClickListener(new OnClickListener()  {

        public void onClick(View v) {
          
            
            speakTextTxt = "Hello world Hello world Hello world Hello world Hello world";
            HashMap<String, String> myHashRender = new HashMap<String, String>();
            myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speakTextTxt);

            String exStoragePath = Environment.getExternalStorageDirectory().getAbsolutePath();
            Log.d("MainActivity", "exStoragePath : "+exStoragePath);
            File appTmpPath = new File(exStoragePath + "/audiofiles/");
            boolean isDirectoryCreated = appTmpPath.mkdirs();
            Log.d("MainActivity", "directory "+appTmpPath+" is created : "+isDirectoryCreated);
            String tempFilename = "audio01.mp3";
            tempDestFile = appTmpPath.getAbsolutePath() + File.separator + tempFilename;
            Log.d("MainActivity", "tempDestFile : "+tempDestFile);
            new MySpeech(speakTextTxt);
        }
    });
}

class MySpeech implements OnInitListener
{

            String tts;

    public MySpeech(String tts)
    {
        this.tts = tts;
        mTts = new TextToSpeech(MainActivity.this, this);
    }

    public void onInit(int status) 
    {
        Log.d("MainActivity", "onInit() called");
        
        int i = mTts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);
        if(i == TextToSpeech.SUCCESS)
        {
                                              
          Toast toast = Toast.makeText(MainActivity.this, "Saved "+i, Toast.LENGTH_SHORT);
          toast.show();   
          
        path = "/mnt/sdcard/audiofiles/audio01.mp3";
     
        //FileInputStream fis;
        
         
        MediaPlayer  mMediaPlayer = new MediaPlayer();
        try {
            //fis = new FileInputStream();
            mMediaPlayer.setDataSource("/mnt/sdcard/audiofiles/audio01.mp3");
            mMediaPlayer.prepare();
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        mMediaPlayer.start();
        }
        else {
            Log.v("MainActivity", "error saving wav file : "+i);
        }
    }
  }
 
}

Edit2:

I tried with the following code, still I am getting same error.

class MySpeech implements OnInitListener
{

            String tts;

    public MySpeech(String tts)
    {
        this.tts = tts;
        mTts = new TextToSpeech(MainActivity.this, this);
    }

    public void onInit(int status) 
    {
        Log.d("MainActivity", "onInit() called");
        
        int i = mTts.synthesizeToFile(speakTextTxt, myHashRender, tempDestFile);
        if(i == TextToSpeech.SUCCESS)
        {
                                              
          Toast toast = Toast.makeText(MainActivity.this, "Saved "+i, Toast.LENGTH_SHORT);
          toast.show();   
          
        try 
        {
            audioPlayer("mnt/sdcard/audiofiles" , "audio01.mp3");  // your file location
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 


            
        }
        else {
            Log.v("MainActivity", "error saving wav file : "+i);
        }
    }
  }

 public void audioPlayer(String path, String fileName) throws IOException
 {        
        if (mp != null) 
        {   System.out.println("before mp.reset() ");
               mp.reset();     
               System.out.println("after mp.reset() ");
          }

        try 
        {
            System.out.println("after path fileName ");
            mp.setDataSource(path+"/"+fileName);
            System.out.println("after path fileName ");
        } 
        catch (IllegalArgumentException e)
        {
            // TODO Auto-generated catch block
            //mp.reset();
            System.out.println("IllegalArgumentException ");
            e.printStackTrace();
        } 
        catch (IllegalStateException e)
        {
            // TODO Auto-generated catch block
            System.out.println("IllegalStateException ");
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            System.out.println("IOException ");
            e.printStackTrace();
        }
        try 
        {
            mp.prepare();
        } catch (IllegalStateException e) 
        {
            // TODO Auto-generated catch block
            System.out.println("On prepare ");
            e.printStackTrace();
        }  
        System.out.println("Before starting");
        mp.start();
       
      
 }
 
  • 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-06-18T08:17:00+00:00Added an answer on June 18, 2026 at 8:17 am

    Try out playing your file using the below method.

     public class MainActivity extends Activity {
        Button store, play;
        EditText input;
        String speakTextTxt;
        TextToSpeech mTts;
        private String path;
        HashMap<String, String> myHashRender = new HashMap<String, String>();
        String tempDestFile;
        MediaPlayer mMediaPlayer;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        store = (Button) findViewById(R.id.button1);
        play = (Button) findViewById(R.id.button2);
        input = (EditText) findViewById(R.id.editText1);
        mMediaPlayer = new MediaPlayer();
        store.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                speakTextTxt = "Hello world Hello world Hello world Hello world Hello world";
                HashMap<String, String> myHashRender = new HashMap<String, String>();
                myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
                        speakTextTxt);
                String exStoragePath = Environment  .getExternalStorageDirectory().getAbsolutePath();
                Log.d("MainActivity", "exStoragePath : " + exStoragePath);
                File appTmpPath = new File(exStoragePath + "/audiofiles/");
                boolean isDirectoryCreated = appTmpPath.mkdirs();
                Log.d("MainActivity", "directory " + appTmpPath
                        + " is created : " + isDirectoryCreated);
                String tempFilename = "audio01.mp3";
                tempDestFile = appTmpPath.getAbsolutePath() + File.separator
                        + tempFilename;
                Log.d("MainActivity", "tempDestFile : " + tempDestFile); 
                 try {
                        audioPlayer(exStoragePath ,tempFilename);  // your file location
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } 
            }
        });
    }
    public void audioPlayer(String path, String fileName) throws IOException {
        if (mMediaPlayer != null) {
            mMediaPlayer.reset();
        }
        try {
            mMediaPlayer.setDataSource(path + "/" + fileName);
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            // mp.reset();
            e.printStackTrace();
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
     }
    

    EDITED:
    Check the Link HERE it will guide you for how to implement Text to Speech – Implementing pause and resume in TTS using MediaPlayer .

    I hope it will help you..

    Thanks.

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

Sidebar

Related Questions

I am implementing an application which is used to draw images and text.User can
I'm implementing a little chat application where I receive messages from a server, which
I'm implementing an application which want to draw lines in the panel. But the
I'm implementing a web application which will support different views according to different browsers.
I'm implementing a Rails application in which users will be able to store snippets
I am implementing a desktop application in which I want to send an ALT+SPACE
I have a C# application in which I am implementing a drag drop functionality
I am implementing a web application which is powered on the backend via a
I am implementing a ASP.NET MVC 4 application which supports plugins and since today
I am writing an application which is used for drawing widgets/menus/controls etc to create

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.