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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:53:55+00:00 2026-06-09T03:53:55+00:00

I’m trying to get an mp3 file and save it on the phone memory

  • 0

I’m trying to get an mp3 file and save it on the phone memory not the SD card then play it immediately with the Media Player. This code worked well when I used it to do the same thing on the SD card previously so it seems there may be some mistakes in the location where I save and read the mp3.

Here is my code:

try {

            MediaPlayer player = new MediaPlayer();
            URI uri = null;
            try {
                uri = new URI(
                        "http://translate.google.com/translate_tts?tl="
                                + oLanguage + "&q=" + text);
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }

            String FileName = "Audio2.mp3";
            URL u = new URL(uri.toASCIIString());
            HttpURLConnection c = (HttpURLConnection) u.openConnection();
            c.setRequestMethod("GET");
            c.setDoOutput(true);
            c.connect();

//          FileOutputStream f = new FileOutputStream(new File(
//                  Environment.getExternalStorageDirectory()
//                          + "/download/" + FileName));

            FileOutputStream f = openFileOutput(FileName, MODE_PRIVATE);                
            InputStream in = c.getInputStream();
            byte[] buffer = new byte[1024];
            int len1 = 0;
            while ((len1 = in.read(buffer)) > 0) {
                f.write(buffer, 0, len1);
            }
            f.close();

//          player.setDataSource(Environment.getExternalStorageDirectory()
//                      + "/download/" + FileName);

            player.setDataSource("/data/data/com.comm/files/" + FileName);              
            player.prepare();
            player.start()

Logcat:

        07-30 12:23:47.319: W/MediaPlayer(22426): info/warning (1, 26)
    07-30 12:23:47.319: E/MediaPlayer(22426): error (1, -4)
    07-30 12:23:47.319: W/System.err(22426): java.io.IOException: Prepare failed.: status=0x1
    07-30 12:23:47.329: W/System.err(22426):    at android.media.MediaPlayer.prepare(Native Method)
    07-30 12:23:47.329: W/System.err(22426):    at com.comm.Connect.Text(Connect.java:396)
    07-30 12:23:47.329: W/System.err(22426):    at com.comm.Connect$7.onClick(Connect.java:233)
    07-30 12:23:47.329: W/System.err(22426):    at android.view.View.performClick(View.java:2485)
    07-30 12:23:47.329: W/System.err(22426):    at android.view.View$PerformClick.run(View.java:9080)
    07-30 12:23:47.329: W/System.err(22426):    at android.os.Handler.handleCallback(Handler.java:587)
    07-30 12:23:47.329: W/System.err(22426):    at android.os.Handler.dispatchMessage(Handler.java:92)
    07-30 12:23:47.329: W/System.err(22426):    at android.os.Looper.loop(Looper.java:130)
    07-30 12:23:47.329: W/System.err(22426):    at android.app.ActivityThread.main(ActivityThread.java:3687)
    07-30 12:23:47.329: W/System.err(22426):    at java.lang.reflect.Method.invokeNative(Native Method)
    07-30 12:23:47.329: W/System.err(22426):    at java.lang.reflect.Method.invoke(Method.java:507)
    07-30 12:23:47.329: W/System.err(22426):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
    07-30 12:23:47.329: W/System.err(22426):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
    07-30 12:23:47.329: W/System.err(22426):    at dalvik.system.NativeStart.main(Native Method)

And finally do I need to specify any permissions to allow me save to the phone memory?

  • 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-09T03:53:56+00:00Added an answer on June 9, 2026 at 3:53 am

    After doing some research it seems I needed to use I found I needed to use an input stream the code below solved the problem

            FileOutputStream f = null;
                try {
                    f = openFileOutput(FileName, MODE_PRIVATE);
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                InputStream in = c.getInputStream();
                byte[] buffer = new byte[1024];
                int len1 = 0;
                while ((len1 = in.read(buffer)) > 0) {
                    f.write(buffer, 0, len1);
                }
                f.close();
    
                player = new MediaPlayer();
                FileInputStream fis = new FileInputStream("/data/data/com.comm/files/"+ FileName);
                player.reset();
                player.setDataSource(fis.getFD());
                player.prepare();
                player.start();
                fis.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.