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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:13:27+00:00 2026-06-08T13:13:27+00:00

I generate a midi file and write it like this: File output = new

  • 0

I generate a midi file and write it like this:

File output = new File("exampleout.mid");

I think I might need to change this, so it is in the right folder (just a readable/writable folder, perhaps Music/ )

Next I want to play this midi file with MediaPlayer, but I cannot figure out how to load the file.

mediaPlayer = MediaPlayer.create(this, R.raw.test3);

Only loads from the read only directory /res/raw. But if I try something like:

mediaPlayer = MediaPlayer.create(this, "file://exampleout");

It does not work because create needs an integer as input. I experimented with AssetFileDescriptor, but haven’t figured it out yet.

Meanwhile, I want to generate a new midi file and load it in mediaPlayer (chained) to play when the first file finishes playing.

MediaPlayer  mediaPlayer = MediaPlayer.create(Activity.this,R.raw.a1);
mediaPlayer.setOnCompletionListener(new musicCompletionListener());
mediaPlayer.start();
private class musicCompletionListener implements OnCompletionListener {
    @Override
    public void onCompletion(MediaPlayer mediaPlayer) {
mediaPlayer.setDataSource(WHATTOPUTHERE)
        mediaPlayer.release();
    }
}

My Problem is really how to call the file. I cannot use strings apparantly, and the r.raw directory is not possible due to its read only nature. I feel the solution is not so difficult, but I am just easing into java from c++, any help is much appreciated!

  • 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-08T13:13:29+00:00Added an answer on June 8, 2026 at 1:13 pm

    I stored the file in the cache dir, that works!

    File output = new File(getCacheDir() + "/exampleout.mid");
    

    And then calling the file:

        String filePath = null;
        File file = null;
        FileInputStream inputStream = null;
    try {
               filePath = getCacheDir() + "/exampleout.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) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I generate EMMA reports during my build, they look like this <report> <stats> <packages
So I want to dynamically generate a MIDI file on a web request.Coming from
I would like to test a MIDI app and want to generate some MIDI
To generate dependency files I can use something like this to generate dependency files:
I generate my web service from WSDL file. But I need t o define
How generate C# class using mgmtclassgen command for IISWebInfo ?? I test like this:
I generate a texture like this: GLuint id; glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
I generate a coverage.xml output file with the following command. C:\Program Files\NCover\NCover.Console.exe //reg //w
I want to make a rhythm game which pre-generate beat from a midi file.
I generate object ids like this: mongodb_app:gen_objectid() This returns obviously a ObjectId type. 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.