Programming with sounds for android

Asked

Viewed 499 times

1

I want to program sounds on Android but I’m not getting it. I tried the java sound API but Android studio doesn’t recognize it. I want to use MIDI as well. I know you have the package android.media.midi but it only works for versions of android above 23. I want a solution for all versions. Can someone help me?


Thank you all very much for your attention. The code of what I want to do follows 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

I mean, I want to edit MIDI messages. What I don’t understand is why Android Studio doesn’t recognize the Java Sound API (which I’m using). Does anyone know? Oi Márcio Oliveira. About the library you posted I think it is incomplete. There is, for example, the file Shortmessage.java.

  • 1

    See if this is what you’re looking for: How to play a sound using Mediaplayer? and How to play sound on android

  • @Hello, you can post what you’ve tried to do ?

  • You want to play files mid or wants to use/control devices midi connected to an Android device?

  • If you specify what you need better, maybe I can help you synthetically create the audios you need without the need to use lib, but "programming sounds for android" is very vague :-(

1 answer

2

The Mediaplayer class plays MIDI smoothly as the MIDI format is natively supported by Android according to official documentation:

https://developer.android.com/guide/topics/media/media-formats.html

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 MIDI’s, using peripherals, etc., I only know the android.media.midi class 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:

https://android-arsenal.com/details/1/1988

Browser other questions tagged

You are not signed in. Login or sign up in order to post.