Reputation: 1759
I will simulate a piano key-board in android pad. When use press one key, I would like play some sound, I know JetPlayer can play midi file, but in this case, I have no mid file, just one single note, how to do it?
Upvotes: 1
Views: 4173
Reputation: 14472
MIDI and using MP3s are completely different things. You could program MIDI to sound like a piano but you will have to do a lot of work to get a good result and you need to be aware that the result will depend on the sound hardware of the phone. Android support for MIDI is also very poor and you'll need a lot of code to do the plumbing work. I recommend that you stick with MP3s. 100x20k files is not really that big. You could possibly make them smaller with some additional compression. For things like single notes, you really don't need high quality audio. Try it out on your phone with 16kbps, 32kbps and 64kpbs.
If you go with MP3, You might want to consider using the SoundPool classes. Take a look at the tutorial here
This enables you to create a HashMap with an index for each sound which you can then use to play each individual note. The index could be the key number for example. To play a note, you would simply call the playSound method of the SoundPool with the relevant index.
I'm assuming that you have a limited number of piano keys and therefore, the overhead of loading multiple sound files (your MP3s) is acceptable. If you have a large number, you might need to think about only loading the sound files for keys which are visible to the user in order to keep your memory usage under control.
Upvotes: 2
Reputation: 13541
You can't specifically "play" a piano on the phone.. You have to have a sound byte, that is used for that particular note.
Upvotes: 0