我有一个应用程序,我有一个视频播放器,里面有视频。如果我将手指放在屏幕上超过 0.4 秒,它会完成此活动,启动记录器活动,并自动开始记录。我的问题是:当我将手指从屏幕上移开时,我可以让第二个活动识别出来,这样会停止录制吗?
当我按住屏幕时调用它:
Intent i = new Intent(VideoPlayerActivity.this, VideoRecorderActivity.class);
Bundle extras = new Bundle();
extras.putInt("mode", VideoRecorderModes.SEND_ALL_MODE);
extras.putInt("index", index);
extras.putInt("touches", 2);
i.putExtras(extras);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
mPreview.getHolder().removeCallback(VideoPlayerActivity.this);
mPreview = null;
startActivity(i);
VideoPlayerActivity.this.finish();
这在我的第二个活动中调用,在相机准备好后:
touches = getIntent().getExtras().getInt("touches");
if (touches == 1) {
mySurfaceView.setPressed(true);
recordButton.setEnabled(false);
okButton.setEnabled(false);
recordButton.setImageResource(R.drawable.shutter_pressed);
startTime = System.currentTimeMillis();
timer = new Timer();
timer.schedule(new TimerDisplayTask(), 0, 500);
startRecording();
touches = 0;
System.out.println("----------------here----------");
}
这是第二个活动的表面视图的 SurfaceView onTouch 方法:
mySurfaceView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG, "event : " + event.getAction() + "||is?: " + isRecording);
Log.i(TAG, "touches:" + touches);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//DO NOTHING
break;
case MotionEvent.ACTION_UP:
if (touches == 1 && isRecording) {
Log.i(TAG, "touch up");
timer.cancel();
timer.purge();
if (isRecording) {
mySurfaceView.setEnabled(false);
Log.i("VideoRecorder blabla", "touche enabled record, ok ,surface: " + recordButton.isEnabled() + "| " + okButton.isEnabled() + "|" + mySurfaceView.isEnabled());
stopRecording();
recordButton.setImageResource(R.drawable.shutter);
touches = 0;
}
}
break;
}
return false;
}
});