Relecture d'un fichier midi avec MediaPlayer
Bonjour à tous,
Je veux faire un piano sur android et je ne trouve pas le moyen de relancer la lecture du fichier Midi correspondant à la note jouée.
La première lecture marche bien, mais c'est l'arrêt et la relecture qui posent problème:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
mediaPlayerA10 = MediaPlayer.create(this, R.raw.a10);
mediaPlayerA10.setLooping(false);
.....
//Exécution de la lecture
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(mediaPlayerA10.isPlaying())
{
mediaPlayerA10.stop();
mediaPlayerA10.reset();
}
try {
mediaPlayerA10.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaPlayerA10.start();
}
}); |
Et j'obtiens ce message d'erreur:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
11-27 22:36:43.693: E/MediaPlayer(1430): prepareAsync called in state 8
11-27 22:36:43.693: W/System.err(1430): java.lang.IllegalStateException
11-27 22:36:43.693: W/System.err(1430): at android.media.MediaPlayer.prepare(Native Method)
11-27 22:36:43.693: W/System.err(1430): at com.example.android_hello.MainActivity$9.onClick(MainActivity.java:171)
11-27 22:36:43.703: W/System.err(1430): at android.view.View.performClick(View.java:4084)
11-27 22:36:43.703: W/System.err(1430): at android.view.View$PerformClick.run(View.java:16966)
11-27 22:36:43.703: W/System.err(1430): at android.os.Handler.handleCallback(Handler.java:615)
11-27 22:36:43.703: W/System.err(1430): at android.os.Handler.dispatchMessage(Handler.java:92)
11-27 22:36:43.703: W/System.err(1430): at android.os.Looper.loop(Looper.java:137)
11-27 22:36:43.703: W/System.err(1430): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-27 22:36:43.703: W/System.err(1430): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 22:36:43.703: W/System.err(1430): at java.lang.reflect.Method.invoke(Method.java:511)
11-27 22:36:43.703: W/System.err(1430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-27 22:36:43.703: W/System.err(1430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-27 22:36:43.703: W/System.err(1430): at dalvik.system.NativeStart.main(Native Method)
11-27 22:36:44.542: E/MediaPlayer(1430): Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=1
11-27 22:36:44.542: E/MediaPlayer(1430): error (-38, 0)
11-27 22:36:44.542: E/MediaPlayer(1430): prepareAsync called in state 0
11-27 22:36:44.542: W/System.err(1430): java.lang.IllegalStateException
11-27 22:36:44.542: W/System.err(1430): at android.media.MediaPlayer.prepare(Native Method)
11-27 22:36:44.542: W/System.err(1430): at com.example.android_hello.MainActivity$9.onClick(MainActivity.java:171)
11-27 22:36:44.542: W/System.err(1430): at android.view.View.performClick(View.java:4084)
11-27 22:36:44.542: W/System.err(1430): at android.view.View$PerformClick.run(View.java:16966)
11-27 22:36:44.542: W/System.err(1430): at android.os.Handler.handleCallback(Handler.java:615)
11-27 22:36:44.542: W/System.err(1430): at android.os.Handler.dispatchMessage(Handler.java:92)
11-27 22:36:44.542: W/System.err(1430): at android.os.Looper.loop(Looper.java:137)
11-27 22:36:44.542: W/System.err(1430): at android.app.ActivityThread.main(ActivityThread.java:4745)
11-27 22:36:44.542: W/System.err(1430): at java.lang.reflect.Method.invokeNative(Native Method)
11-27 22:36:44.542: W/System.err(1430): at java.lang.reflect.Method.invoke(Method.java:511)
11-27 22:36:44.542: W/System.err(1430): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-27 22:36:44.542: W/System.err(1430): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-27 22:36:44.542: W/System.err(1430): at dalvik.system.NativeStart.main(Native Method)
11-27 22:36:44.542: E/MediaPlayer(1430): start called in state 0
11-27 22:36:44.562: E/MediaPlayer(1430): Error (-38,0)
11-27 22:36:44.562: E/MediaPlayer(1430): stop called in state 0
11-27 22:36:44.573: E/MediaPlayer(1430): Attempt to perform seekTo in wrong state: mPlayer=0x0, mCurrentState=0 |
J'ai essayé déjà toutes les options possibles: enlever le reset, ajouter un seekTo(0), etc. et toujours des messages d'erreurs...
:help: