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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:46:43+00:00 2026-06-08T20:46:43+00:00

I am dynamically generating midi files (in cache dir) with an android app. After

  • 0

I am dynamically generating midi files (in cache dir) with an android app.

After generation, I play the file with MediaPlayer within the same app.

When running the app for the first time, it already needs the file to be there in the cache directory (the app crashes). It works on the emulator if I use the filemanager to put a dummy file there first. How can I circumvent this?

I need the app to run on a tablet for the first time, without requiring the file.

I am using these commands now:

try {

            filePath = getCacheDir() + "/optimuse" + song + ".mid";
            file = new File(filePath);

            inputStream = new FileInputStream(file);
            if (inputStream.getFD().valid()) {
                System.out.println("Valid!");
            }
        } catch (Exception e1) {
            e1.printStackTrace();
            System.exit(-1);
        }

        try {
            mediaPlayer = new MediaPlayer();
            mediaPlayer.setDataSource(inputStream.getFD());
            inputStream.close();
        } catch (Exception e1) {
            e1.printStackTrace();
            System.exit(-1);
        }

        try {
            mediaPlayer.prepare();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

Is there any way around this?

Thanks!

  • 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-08T20:46:45+00:00Added an answer on June 8, 2026 at 8:46 pm

    Maybe check whether the file exists before using it? You can achieve this using the File#exists() method.

    First, you use the Context#getFileStreamPath(String) method – where the String is the filename of the file you are trying to access. Then you can call File#exists() on the returned object.

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

Sidebar

Related Questions

I'm dynamically generating RDL files for SSRS 2008, assembling my reports from building blocks
I'm dynamically generating a Windows Forms form by reading an XML file. (Actually I
Have a program that's dynamically generating an Excel file and a csv. The excel
I am dynamically generating (in a PHP script) a .mobileconfig file for iOS devices
I'm dynamically generating a layout, and to do this I have a menu_row_element.xml file
I'm dynamically generating a textbox and a dropdownlist in my ASP.NET web app table
I am dynamically generating html file. It is formated with Css and Images. I
I am dynamically generating rss ouput from a php file and the url to
i'm dynamically generating asp controls inside an update panel on a certain trigger. However,
I am dynamically generating image in php. The image has a fixed name. I

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.