2017-02-06 2 views
0

Obtention d'une erreur IOException lors de la mise en place de la source URI dans un objet de MediaPlayer à l'aide de setDataSource. Essayer d'obtenir Uri d'une chanson mobile en utilisantErreur IOException lors de la mise à l'état initial de la source URI dans Media Player (setDataSource)

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI); 
startActivityForResult(intent, 10); 

onActivityResult

@Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 

      if(resultCode == RESULT_OK && requestCode == 10){ 
       Uri uriSound=data.getData(); 
       Toast.makeText(getApplicationContext(),"It Came Here",Toast.LENGTH_SHORT).show(); 
       play_sound(uriSound); 
      } 
     } 

play_sound

private void play_sound(Uri uri) { 


      Toast.makeText(getApplicationContext(),"It Came Here 2" + uri,Toast.LENGTH_LONG).show(); 

      MediaPlayer mp = new MediaPlayer(); 

      try { 

       mp.setDataSource(getApplicationContext(), uri); 
       mp.start(); 
      } catch (IllegalArgumentException e) { 

       Toast.makeText(getApplicationContext(),"Error 1",Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } catch (SecurityException e) { 
       Toast.makeText(getApplicationContext(),"Error 2",Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } catch (IllegalStateException e) { 
       Toast.makeText(getApplicationContext(),"Error 3",Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } catch (IOException e) { 
       Toast.makeText(getApplicationContext(),"Error 4",Toast.LENGTH_LONG).show(); 
       e.printStackTrace(); 
      } 

     } 

I Used Toast de vérifier où erreur. Obtenir une erreur dans "IOException e" Je ne sais pas ce que c'est sur googling tout ce que je reçois est qu'il est SOme sorte de "format de fichier" problème du fichier sélectionné.

Répondre

0

Résolu !! Just Ajout d'une ligne dans la lecture du son

mP.setAudioStreamType(AudioManager.STREAM_MUSIC); 

play_sound (Uri uri):

private void Play_Sound(Uri uri) 
     { 
      MediaPlayer mPlayer = new MediaPlayer(); 
      mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
      try { 
       mPlayer.setDataSource(getApplicationContext(), uri); 
      } catch (IllegalArgumentException e) { 
       Toast.makeText(getApplicationContext(), "You might 1 not set the URI correctly!", Toast.LENGTH_LONG).show(); 
      } catch (SecurityException e) { 
       Toast.makeText(getApplicationContext(), "You might 2 not set the URI correctly!", Toast.LENGTH_LONG).show(); 
      } catch (IllegalStateException e) { 
       Toast.makeText(getApplicationContext(), "You might 3 not set the URI correctly!", Toast.LENGTH_LONG).show(); 
      } catch (IOException e) { 
       Toast.makeText(getApplicationContext(), "You might 4 not set the URI correctly!", Toast.LENGTH_LONG).show(); 

       e.printStackTrace(); 
      } 
      try { 
       mPlayer.prepare(); 
      } catch (IllegalStateException e) { 
       Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
      } catch (IOException e) { 
       Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show(); 
      } 
      mPlayer.start(); 
     }