我正在尝试使用模拟器中的相机录制视频。录制后,我希望 VideoView 在剪辑中显示 1 毫秒的预览图像。然后在 VideoView 上添加一个 MediaController。用户必须单击一个按钮来创建激活 ACTION_VIDEO_CAPTURE 的意图。请参阅此处的UI 布局。
我可以在模拟器的相机应用程序中进行录制,但问题是我什至无法让它立即在 VideoView 中播放。如何在第一段中实现我的目标?我没有从设备或 Logcat 中收到任何错误消息。录制后,它只是回到空白的videoView。会不会是视频格式?
仅供参考,我在同一个屏幕上有一个 ImageView,它工作得非常好。
onCreate 方法
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_new_card);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("Create a new activity card");
activity_title = findViewById(R.id.activity_title);
imageView = findViewById(R.id.imageView);
editText_hrs = findViewById(R.id.editText_hrs);
editText_mins = findViewById(R.id.editText_mins);
videoBtn = findViewById(R.id.uploadVideo);
videoView = findViewById(R.id.videoView);
checkbox = findViewById(R.id.check_useofitems);
createcard_done = findViewById(R.id.createcard_done);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
imageutils = new ImageUtils(this);
imageView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
imageutils.imagepicker(1);
}
});
videoUtils = new VideoUtils(this);
videoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//videoUtils.videoPicker(1);
//videoView.setVideoURI(videoUtils.getVideoUri());
Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
if(videoIntent.resolveActivity(getPackageManager()) != null){
startActivityForResult(videoIntent, VIDEO_REQUEST);
}
}
});
videoView.setVideoURI(videoUri);
videoView.start();
onActivityResult 方法
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch(requestCode) {
case 0:
imageutils.onActivityResult(requestCode, resultCode, data);
break;
case 1:
if (resultCode == RESULT_OK) {
videoUri = data.getData();
}
break;
}
}