Programming with sounds for android

1

I want to program sounds on Android but I can not. I tried the java sound API but Android studio does not recognize it. I want to use MIDI too. I know it has the android.media.midi package but it only works for android versions above 23. I want a solution for all versions. Can anyone help me?

Thank you all for your attention. The code I want to do is below:

    ShortMessage myMsg = new ShortMessage();
    // Play the note Middle C (60) moderately loud
    // (velocity = 93)on channel 4 (zero-based).

    myMsg.setMessage(ShortMessage.NOTE_ON, 4, 60, 93);
    Synthesizer synth = null;
    synth = MidiSystem.getSynthesizer();
    Receiver synthRcvr = null;
    synthRcvr = synth.getReceiver();
    synthRcvr.send(myMsg, -1); // -1 means no time stamp

That is, I want to edit MIDI messages. What I do not understand is why Android Studio does not recognize the Java Sound API (which I'm using). Anybody know? Hi Márcio Oliveira. About the library you posted I think this is incomplete. There is, for example, no file ShortMessage.java.

    
asked by anonymous 06.06.2017 / 05:35

1 answer

2

The MediaPlayer class plays MIDI seamlessly because the MIDI format is supported natively by Android according to official documentation:

link

Here's a simple example with MediaPlayer (put a midi file in the "res / raw" folder):

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

//Se quiser pausar
mediaPlayer.pause()

// Se quiser avançar para os primeiros 30 segundos
mediaPlayer.seekTo(30000);

If you want to do more advanced things like editing MIDIs, using peripherals, etc., I only know the class android.media.midi even though it was only introduced in API 23 (Marshmallow). You can take a look at this library here, but I've never used it:

link

    
06.06.2017 / 15:50