无法从 SD 卡打开播放 VideoView 中的此视频

cannot open play this video in VideoView from sd card

您好,我正在尝试播放 phone 在 VideoView 中的内部存储器中的视频,但我的 phone 提示 "cannot play this video"。我在主 activity 中获取视频路径,将其传递给投影仪 activity。

这是路径:'/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4'

OnCreate 代码:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_projector);

        Intent intent = getIntent();
        String vidpath = intent.getExtras().getString("path");
        p = (TextView) findViewById(R.id.videopath);
        p.setText(vidpath);

        Uri path= Uri.parse(Environment.getExternalStorageDirectory()+vidpath);

        viewvid=(VideoView) this.findViewById(R.id.videoView);
        Log.i("vidpath","here");
        viewvid.setVideoURI(path);
        viewvid.start();


    }

这是我从 MainActivity 获取视频路径的方式:

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        getSupportActionBar().setTitle("Video Projector");
        gall = (Button) findViewById(R.id.gallery);
        gall.setOnClickListener(this);
    }

    @ Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK) {
            if (requestCode == SELECT_VIDEO) {
                selectedVideoPath = getPath(data.getData());
                if(selectedVideoPath == null) {
                    finish();
                } else {
                    Toast.makeText(this,"A Video was selected",Toast.LENGTH_LONG).show();
                    Intent i = new Intent(this,projector.class);
                    i.putExtra("path",selectedVideoPath);
                    startActivity(i);
                }
            }
        }
        finish();
    }

    public String getPath(Uri uri) {
        String[] projection = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
        if(cursor!=null) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
            cursor.moveToFirst();
            return cursor.getString(column_index);
        }
        else return null;
    }



    @Override
    public void onClick(View v) {
        if (v==gall)
        {
            Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI);
            startActivityForResult(i, SELECT_VIDEO);
        }
    }

这是日志:

09 - 11 09: 48: 33.341 27291 - 27291 / com.example.tabish.vidprojector W / MediaPlayer: Couldn 't open /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4: java.io.FileNotFoundException: No content provider: /storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4
09 - 11 09: 48: 33.342 27291 - 27291 / com.example.tabish.vidprojector I / MediaPlayer: setDataSource(/storage/emulated / 0 / storage / emulated / 0 / snaptube / download / SnapTube Video / Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.342 547 - 628 / ? I / MediaPlayerService : setDataSource(/storage/emulated / 0 / storage / emulated / 0 / snaptube / download / SnapTube Video / Justin Bieber - Sorry(PURPOSE _ The Movement).mp4)
09 - 11 09: 48: 33.365 547 - 27641 / ? E / FileSource : Failed to open file '/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - Sorry (PURPOSE _ The Movement).mp4'.(No such file or directory)

已解决: 第 1 步: 使用 Uri path=Uri.fromFile(new File(vidpath)); 第 2 步: 在 phone

的应用程序管理器中检查您的应用的 存储权限