Autore Topic: list view  (Letto 325 volte)

Offline pegaso993

  • Utente junior
  • **
  • Post: 84
  • Respect: 0
    • Mostra profilo
  • Dispositivo Android:
    note 2
  • Sistema operativo:
    android
list view
« il: 01 Ottobre 2013, 20:02:58 CEST »
0
cosa sbagli voglio avviare un altro lettore player e stoppare quello che c'è avviato

   public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
      if(position == 0)
      {
         
         final String pathToFile = "http://mp3.kataweb.it:8000/RadioDeejay";
         final MediaPlayer mMediaPlayer = new MediaPlayer();
         mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
         mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);
          
         mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
               @Override
               public void onPrepared(MediaPlayer mp) {
               // do stuff here
                  mMediaPlayer.start();
               }});
          
           try {
              mMediaPlayer.setDataSource(pathToFile);
         } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (SecurityException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
           try {
              mMediaPlayer.prepareAsync();
         } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
         }
           mMediaPlayer.start();
           button3.setOnClickListener(new OnClickListener() {
            public void onClick(View view) {
               
               if (mMediaPlayer != null) {
                  mMediaPlayer.pause();
                  Context context = getBaseContext();
                      Intent myIntent = new Intent(context, Podcast.class);
                     startActivityForResult(myIntent, 0);
      }   }
            });
      }
      if (position == 1 ) {
          mMediaPlayer.stop();
      
           }
      }
      

però una volta avviata l app se clicco nel primo elemento parte poi se clicco il secondo l'app crasha