Cwac Camera Video PreviewFragment

50 Views Asked by At

I am implementing Cwac-camera for video recording within my application. I am trying to figure out how can I setup my Video Preview Fragment which will playback the Video Recorded within the fragment with replay in infinite until the user has accepted or rejected the video preview.

This is my Activity where it calls for the video fragment.

  @Override
    public void onVideoRecorded(File video) {

        videoPreviewFragment = VideoPreviewFragment.newInstance(video);

        getSupportFragmentManager().beginTransaction().replace(R.id.sc_camera_container, picturePreviewFragment).commit();
    }

And the VideoPreviewFragment I am using File to instead of URi

public class VideoPreviewFragment extends Fragment implements MediaPlayer.OnCompletionListener {

    private static final String EXTRA_VIDEO_LOCATION = "extra_video_location";

    public static VideoPreviewFragment newInstance(File video) {
        VideoPreviewFragment fragment = new VideoPreviewFragment();

        Bundle args = new Bundle(1);
        args.putString(EXTRA_VIDEO_LOCATION, video.toString());

        fragment.setArguments(args);

        return fragment;
    }

    private VideoView videoView;
    private File video;

    private ImageButton btnAccept;
    private ImageButton btnReject;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.sc_video_preview, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        videoView = (VideoView) view.findViewById(R.id.sc_video);

        btnAccept = (ImageButton) view.findViewById(R.id.sc_btn_accept);
        btnAccept.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getCameraActivity().onAccept(video);
            }
        });

        btnReject = (ImageButton) view.findViewById(R.id.sc_btn_reject);
        btnReject.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getCameraActivity().onReject(video);
            }
        });

        video = new File(getArguments().getString(EXTRA_VIDEO_LOCATION));
    }


    public SimpleCameraActivity getCameraActivity() {
        return (SimpleCameraActivity) getActivity();
    }

    @Override
    public void onSuccess() {

        btnAccept.setEnabled(true);
        btnReject.setEnabled(true);
    }

    @Override
    public void onError() {

        btnAccept.setEnabled(false);
        btnReject.setEnabled(false);
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        Log.e("VIDEO PLAY", "END VIDEO PLAY");
    }

}
0

There are 0 best solutions below