此功能用于返回单击某些图像时要播放的视频URL
public String alphabetf(int a){
String video_url =new String();
switch (a){
case R.drawable.a:
video_url= "android.resource://" + getPackageName() + "/" + R.raw.a;
break;
case R.drawable.b:
video_url = "android.resource://" + getPackageName() + "/" + R.raw.b;
break;
default:
video_url = "android.resource://" + getPackageName() + "/" + R.raw.a;
}
return video_url;
}
调用函数。
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video_view);
VideoView mVideoView =(VideoView)findViewById(videoView) ;
mVideoView.setZOrderOnTop(true);
Intent intent = getIntent();
String alphabet = intent.getStringExtra("alphabetName").toString();
int imageId =intent.getIntExtra("imageId",0);
Log.w("myApp", alphabet);
Log.w("id", String.valueOf(imageId));
Uri videoUri;
videoUri = Uri.parse(alphabetf(imageId));
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(mVideoView);
mVideoView.setMediaController(mediaController);
mVideoView.setVideoURI(videoUri);
mediaController.requestFocus();
mVideoView.start();
}
以上功能仅返回默认值
错误:
W/MediaPlayer: Couldn't open : java.io.FileNotFoundException: No content provider:
W/VideoView: Unable to open content:
java.io.IOException: setDataSource failed.
我正在使用cardview,并且我想在新活动中打开与图像相关的视频。