Android使用默认音乐播放器播放AMR文件

时间:2013-07-16 10:04:39

标签: android android-intent

我的SD卡中有少量AMR文件。我想使用默认的Android音乐播放器播放这些amr文件。 TODO这个,我试过下面的代码:

        Uri myUri = Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myfiles/filename.amr");
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
    intent.setDataAndType(myUri, "audio/*");
    startActivity(intent);

和我的stacktrace:

07-16 15:23:47.284: D/Instrumentation(32496): checkStartActivityResult :Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/myfiles/filename.amr typ=audio/* }
07-16 15:23:47.284: D/Instrumentation(32496): checkStartActivityResult inent is instance of inent: 07-16 15:23:47.284: D/AndroidRuntime(32496): Shutting down VM
07-16 15:23:47.284: W/dalvikvm(32496): threadid=1: thread exiting with uncaught exception (group=0x414feac8)
07-16 15:23:47.304: E/AndroidRuntime(32496): FATAL EXCEPTION: main
07-16 15:23:47.304: E/AndroidRuntime(32496): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/storage/emulated/0/myfiles/filename.amr typ=audio/* }
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Activity.startActivityForResult(Activity.java:3430)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Activity.startActivityForResult(Activity.java:3391)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Activity.startActivity(Activity.java:3626)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.Activity.startActivity(Activity.java:3594) 07-16 15:23:47.304: E/AndroidRuntime(32496): at com.example.ui.MainActivity.onItemClick(MainActivity.java:85)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.widget.AdapterView.performItemClick(AdapterView.java:301)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.widget.AbsListView.performItemClick(AbsListView.java:1502)
07-16 15:23:47.304: E/AndroidRuntime(32496): at android.widget.AbsListView$PerformClick.run(AbsListView.java:3250) 07-16 15:23:47.304: E/AndroidRuntime(32496): at android.widget.AbsListView$1.run(AbsListView.java:4299) 07-16 15:23:47.304: E/AndroidRuntime(32496): at android.os.Handler.handleCallback(Handler.java:725) 07-16 15:23:47.304: E/AndroidRuntime(32496): at android.os.Handler.dispatchMessage(Handler.java:92) 07-16 15:23:47.304: E/AndroidRuntime(32496): at android.os.Looper.loop(Looper.java:137) 07-16 15:23:47.304: E/AndroidRuntime(32496): at android.app.ActivityThread.main(ActivityThread.java:5227)
07-16 15:23:47.304: E/AndroidRuntime(32496): at java.lang.reflect.Method.invokeNative(Native Method)
07-16 15:23:47.304: E/AndroidRuntime(32496): at java.lang.reflect.Method.invoke(Method.java:511) 07-16 15:23:47.304: E/AndroidRuntime(32496): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 07-16 15:23:47.304: E/AndroidRuntime(32496): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 07-16 15:23:47.304: E/AndroidRuntime(32496): at dalvik.system.NativeStart.main(Native Method)

我怎样才能做到这一点? 当在文件管理器中打开此amr时,它会显示一个对话框,用于选择可用的音乐播放器并开始播放。我希望实现这一目标。

my target to achieve to get this pop up in my app

1 个答案:

答案 0 :(得分:0)

尝试将mimeType设置为“audio / amr”而不是“audio / *”。 也许你也必须这样做     “file://”+ Environment.getExternalStorageDirectory()

见这里:what is the issue i am Not able to open the native player to play the recorded file?