【问题标题】:Mediaplayer not opening selected file android (setDataSource failed.: status=0x80000000)Mediaplayer 没有打开选定的文件 android (setDataSource failed.: status=0x80000000)
【发布时间】:2017-04-02 00:30:06
【问题描述】:

所以我设置了以下代码来从内存中挑选一首歌曲并播放它。

Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
                            startActivityForResult(intent, 10);

我的 onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(resultCode == RESULT_OK){
        Uri uriSound = data.getData();

        play(this, uriSound);
    }
}

最后是我的玩法: private void play(Context context, Uri uri) {

    MediaPlayer mip = new MediaPlayer();
    try {

        mip.setDataSource(context, uri);
        mip.prepare();
        mip.start();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

但是当我运行它时,我不断收到以下错误:

java.io.IOException: setDataSource failed.: status=0x80000000

我无法在任何地方找到可行的解决方案。 有什么想法吗?

【问题讨论】:

    标签: java android android-mediaplayer


    【解决方案1】:

    在清单文件中授予读取外部存储的权限已修复它!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-30
      • 1970-01-01
      相关资源
      最近更新 更多