gpt4 book ai didi

mp4 - 无法从 SD 卡在 VideoView 中打开播放此视频

转载 作者:行者123 更新时间:2023-12-04 20:47:58 24 4
gpt4 key购买 nike

嗨,我正在尝试在 VideoView 中播放手机内部存储中的视频,但我的手机提示“无法播放此视频”。我在主要事件中获取视频路径,将其传递给投影仪事件。

这是路径:'/storage/emulated/0/storage/emulated/0/snaptube/download/SnapTube Video/Justin Bieber - 抱歉(目的 _ 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)

最佳答案

已解决:
第一步:使用 Uri path=Uri.fromFile(new File(vidpath)); 第二步:检查 存储权限用于您手机应用程序管理器中的应用程序

关于mp4 - 无法从 SD 卡在 VideoView 中打开播放此视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46148475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com