Picking up an audio file android

后端 未结 5 1105
花落未央
花落未央 2021-01-31 19:11

I need to fetch an audio file from SD Card and play it. I think this can be done by getting URI of an audio file. So, to pick an audio file I\'m using following code:

         


        
5条回答
  •  甜味超标
    2021-01-31 19:47

    //To pick audio file from device. Place below code in calling activity

    int REQUEST_CODE = 1001;
    
     Intent audioIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
     startActivityForResult(audioIntent,REQUEST_CODE);
    

    // Override onActivityForResult method in activity

    @Override 
    protected void onActivityResult(int requestCode,int resultCode,Intent data){
    
      if(requestCode == REQUEST_CODE && resultCode == RESULT_OK ){
    
            //the selected audio.Do some thing with uri
            Uri uri = data.getData(); 
    
    
      }
    
      super.onActivityResult(requestCode, resultCode, data);
    }
    

提交回复
热议问题