问题
I am trying to play midi file using fmod. But there is an error says that :a resource that the plugin requires cannot be found,(ie the DLS file for MIDI playback)
I have searched results for problems like this,and referred to the fmod.h files. It seems that I need a file named "gs_instrument.dls" but I cannot find it in my mac as well as the android simulator filesystem. I have also searched the resources in the web,no result either.
So what should I do if I want to play midi file in android using fmod.
Hope you can help me!
Thanks!
回答1:
I don't know about fmod, but Android can play MIDI files right out of the box. Here's a simplified version of what works for me:
MediaPlayer mediaPlayer = new MediaPlayer();
File f = [... my MIDI file ...];
FileInputStream fis = new FileInputStream(f);
FileDescriptor fd = fis.getFD();
mediaPlayer.setDataSource( fd );
mediaPlayer.prepare();
mediaPlayer.start();
回答2:
You specify the location of the DLS file with the dlsname member of the FMOD_CREATESOUNDEXINFO structure passed into System::createSound.
You must provide the actual file yourself and put it on the sdcard so you can pass in the location of it. On Windows the default DLS file is located at "C:\Windows\System32\drivers\gm.dls" or "C:\Windows\System32\drivers\etc\gm.dls". Alternatively on Mac it is located at "/System/Library/Components/CoreAudio.component/Contents/Resources/gs_instruments.dls". This being said I cannot speak to the legality of using these files in an Android project, you may need to source your own "free" dls file from somewhere else.
回答3:
You can use like this. You can call following method where you want to play midi file.
public void myRingCtone()
{
Uri path = Uri.parse("android.resource://com.PackageName/raw/MIDI_RingToneName");
RingtoneManager.setActualDefaultRingtoneUri(getApplicationContext(),
RingtoneManager.TYPE_RINGTONE, path);
Log .i("TESTT", "Ringtone Set to Resource: "+ path.toString());
RingtoneManager.getRingtone(getApplicationContext(), path).play();
}
来源:https://stackoverflow.com/questions/7010662/how-to-play-midi-file-in-android-use-fmod