I am trying to integrate this library in my fragment. In this tutorial they have said to call fragment.viewLifecycleOwner instead of this in camera.setLifecycleOwner(this). I have followed all the process to start video recording. I tried to debug it also but after calling camera.startCapturingVideo(file) its not getting a callback for onVideoTaken(). My video file is getting created in the path but while playing it, it's showing can't play this video.I think it's because I am not getting a callback. Below is my Fragment:
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
covered = InhalerData.getInstance().manifest.getPlayerType();
if (covered != null) {
if (covered.equalsIgnoreCase("covered")) {
view = inflater.inflate(R.layout.fragment_video, container, false);
} else {
view = inflater.inflate(R.layout.fragment_video_side_by_side, container, false);
}
}
mContext = getActivity();
setViews();
return view;
}
private void setViews() {
//initializing views
video = view.findViewById(R.id.video);
textureView = view.findViewById(R.id.camera_texture);
parentLayout = view.findViewById(R.id.parent_layout);
overLay = view.findViewById(R.id.overlay);
tv_tips = view.findViewById(R.id.tips);
textureView.setLifecycleOwner(VideoPlayerFragment.this);
return true;
}
});
textureView.addCameraListener(new CameraListener() {
@Override
public void onVideoTaken(File video) {
super.onVideoTaken(video);
onVideo(video);
}
});
}
//This method is called on record button click
private void captureVideo(String name) {
if (textureView.getSessionType() != SessionType.VIDEO) {
return;
}
isRecordingOn = false;
File mediaFile =
new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ "/" + name + VIDEO_EXTENSION);
textureView.setVideoCodec(VideoCodec.H_264);
textureView.startCapturingVideo(mediaFile, 8000);
if (mRecordingTimer != null) {
mRecordingTimer.start();
}
startBlinking();
textureView.postDelayed(new Runnable() {
@Override
public void run() {
// This will trigger onVideoTaken().
textureView.stopCapturingVideo();
}
}, 8000);
}
How can I add a callBack in fragment, What should I pass instead of this.