Cwac Camera Video PreviewFragment

时间:2016-02-02 16:30:57

标签: android android-fragments video cwac-camera

我正在我的应用程序中实现用于视频录制的Cwac相机。我试图找出如何设置我的视频预览片段,它将播放片段中录制的视频,并且无限重播,直到用户接受或拒绝视频预览。

这是我调用视频片段的活动。

  @Override
    public void onVideoRecorded(File video) {

        videoPreviewFragment = VideoPreviewFragment.newInstance(video);

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

VideoPreviewFragment我使用的是File而不是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 个答案:

没有答案