How to pickup an audio file's path or uri from device in Android?

后端 未结 1 491
误落风尘
误落风尘 2020-12-30 12:27

I am creating an simple app where I want to play a sound. On pressing a button play on app it will play the sound. For playing sound I am using:

MediaPlayer          


        
相关标签:
1条回答
  • 2020-12-30 12:40

    Just use, these two lines,

    Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(Intent.createChooser(intent, "Gallery"), reqCode);
    

    Or,

     Intent intent = new Intent();
            intent.setType("audio/*");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            startActivityForResult(Intent.createChooser(intent,"Select Audio "), reqCode);
    
    0 讨论(0)
提交回复
热议问题