我正在创建一个简单的应用程序,我想播放声音.按下应用程序上的按钮播放它将播放声音.为了播放我正在使用的声音:
MediaPlayer mediaPlayer;
mediaPlayer = MediaPlayer.create(this, R.raw.test_cbr);
mediaPlayer.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Completed",
Toast.LENGTH_LONG).show();
}
});
mediaPlayer.start();
Run Code Online (Sandbox Code Playgroud)
它工作正常.
但是现在我希望用户能够从设备中选择音频文件,这样当他或她按下播放按钮时,应该播放所选择的声音.
我没有得到像图像可以采摘的任何意图行动.
Intent photo_picker_intent = new Intent(Intent.ACTION_PICK);
photo_picker_intent.setType("image/*");
startActivityForResult(photo_picker_intent, PHOTOS_FROM_GALLERY);
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,用户只需访问图库.单击任何图像后,他或她将获得可用于在应用程序中显示图像的图像URI.我想做同样的事情,除了音频文件选择.
use*_*305 16
只需使用这两行,
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(Intent.createChooser(intent, "Gallery"), reqCode);
Run Code Online (Sandbox Code Playgroud)
要么,
Intent intent = new Intent();
intent.setType("audio/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Audio "), reqCode);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7581 次 |
| 最近记录: |