Bonjour,

Est-il possible de lire une suite de musique avec MediaPlayer ?
J'essai de lancer les musiques l'une après l'autre mais sans succès...

Avec mon script je n'ai aucun souci pour lire le premier titre mais quand celui-ci est fini et que je voudrai que le MediaPlayer passe à l'autre j'ai l'erreur suivant :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
12-31 22:35:56.914: E/AndroidRuntime(16748): FATAL EXCEPTION: main
12-31 22:35:56.914: E/AndroidRuntime(16748): java.lang.IllegalStateException
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.media.MediaPlayer._stop(Native Method)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.media.MediaPlayer.stop(MediaPlayer.java:961)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.mon.lecteur.PlayerService.stop(PlayerService.java:130)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.mon.lecteur.PlayerService.play(PlayerService.java:104)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.mon.lecteur.PlayerService.checkLecture(PlayerService.java:116)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.mon.lecteur.PlayerService.access$0(PlayerService.java:109)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.mon.lecteur.PlayerService$2.onCompletion(PlayerService.java:74)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:1448)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.os.Handler.dispatchMessage(Handler.java:99)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.os.Looper.loop(Looper.java:123)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at android.app.ActivityThread.main(ActivityThread.java:3687)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at java.lang.reflect.Method.invokeNative(Native Method)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at java.lang.reflect.Method.invoke(Method.java:507)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
12-31 22:35:56.914: E/AndroidRuntime(16748): 	at dalvik.system.NativeStart.main(Native Method)
Voici la section de code qui gère la lecture :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
 
private void play() {
    if (!isPlaying) {
 
      // Préparation des données de la musique
      String url_morceau = URL;
      String titre_morceau = mon_titre;
 
      try {
    	mediaplayer = new MediaPlayer();
 
		mediaplayer.setDataSource(url_morceau);
		mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
 
		mediaplayer.setOnPreparedListener(new OnPreparedListener() {
			//
			public void onPrepared(MediaPlayer mp) {
				// Quand le listener est déclenché on lance la musique
				mp.start();
			}
		});
		// Listener déclenché a la fin de la lecture du titre
		mediaplayer.setOnCompletionListener(new OnCompletionListener() {
			public void onCompletion(MediaPlayer mp) {
				// Quand la lecture d'un titre est terminé
				 mp.stop();
			     mp.release();
			      checkLecture();
			}
		});
		mediaplayer.prepareAsync();	
      } catch (IllegalArgumentException e) {
    	 Toast.makeText(PlayerService.this, "Musique illisible ou irrécupérable", Toast.LENGTH_SHORT).show();
      } catch (IllegalStateException e) {
			// TODO Auto-generated catch block
    	  Toast.makeText(PlayerService.this, "Statut du média invalide", Toast.LENGTH_SHORT).show();
      } catch (IOException e) {
			// TODO Auto-generated catch block
    	  Toast.makeText(PlayerService.this, "Erreur - Exception I/O", Toast.LENGTH_SHORT).show();
      }
 
      Notification note=new Notification(R.drawable.little_icon_player,titre_morceau,System.currentTimeMillis());
      Intent i=new Intent(this, LecteurActivity.class);
 
      i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
 
      PendingIntent pi=PendingIntent.getActivity(this, 0,
                                                  i, 0);
 
      note.setLatestEventInfo(this, "Lecteur",titre_morceau,pi);
      note.flags|=Notification.FLAG_NO_CLEAR;
      isPlaying = true;
      startForeground(1337, note);
    }else{
    	stop();
    	play();
    }
  }
 
  private void checkLecture(){
  	 // Fait des vérif et relance play()
   }
 
  private void stop() {
    if(isPlaying) {
      mediaplayer.stop();
      mediaplayer.release();
      Log.w(getClass().getName(), "On est dans stop()!");
      stopForeground(true);
    }
  }
Merci par avance.
Cordialement.