0

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");
    }

}
Sagar Atalatti
  • 486
  • 1
  • 8
  • 21
  • "I am implementing Cwac-camera for video recording within my application" -- that library has been discontinued. Beyond that, Stack Overflow is for programming questions. What is your question? – CommonsWare Feb 02 '16 at 17:18
  • Then should I go with the cwac-cam2 for the implementation ? I am video recording implemented for which I am trying to build video preview playback after the video has been recorded. – Sagar Atalatti Feb 02 '16 at 17:33
  • I had tried working with the cwac-cam2 but I couldn't work around with the UI implementations. – Sagar Atalatti Feb 02 '16 at 17:34
  • "Then should I go with the cwac-cam2 for the implementation ?" -- most likely, you should be using the camera APIs directly. The CWAC camera libraries are for *very* simple scenarios. If taking pictures is more than 1% of the functionality of your app, use the camera APIs directly. – CommonsWare Feb 02 '16 at 17:45

0 Answers0