如何皮卡音频文件的路径或URI从设备的Andr​​oid? [英] How to pickup an audio file's path or uri from device in Android?

查看:110
本文介绍了如何皮卡音频文件的路径或URI从设备的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个简单的应用程序,我想打一个声音。在$ P $在App pssing一键播放,将播放声音。 对于播放声音我使用的:

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 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();

和它工作正常。

但现在我想用户应该能够选择从设备中的音频文件,这样当他(她)presses的播放按钮,选定的声音应发挥。

But now I want that the user should be able to select a audio file from device, so that when he or she presses the play button, the selected sound should be played.

我没有收到类似图像的任何意图动作可以采摘。

I am not getting any intent action like image can be picked.

Intent photo_picker_intent = new Intent(Intent.ACTION_PICK);
photo_picker_intent.setType("image/*");
startActivityForResult(photo_picker_intent, PHOTOS_FROM_GALLERY);

在上面的code,用户只需去画廊。当点击在任何图像,他或她将得到的图像的URI可用于表示应用程序的图像。我想这样做,除了音频文件的选择。

In the above code, the user will simply go to gallery. Upon clicking on any image, he or she will get an image URI that can be used for showing image in app. I would like to do the same, except for an audio file selection.

推荐答案

只要使用,这两条线,

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

或者

 Intent intent = new Intent();
        intent.setType("audio/*");
        intent.setAction(Intent.ACTION_GET_CONTENT);
        startActivityForResult(Intent.createChooser(intent,"Select Audio "), reqCode);

这篇关于如何皮卡音频文件的路径或URI从设备的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆