|
| 1 | +package com.omega_r.omegaintentbuilder; |
| 2 | + |
| 3 | +import android.content.Intent; |
| 4 | +import android.net.Uri; |
| 5 | +import android.os.Bundle; |
| 6 | +import android.util.Log; |
| 7 | +import android.view.View; |
| 8 | +import android.widget.Toast; |
| 9 | +import android.widget.VideoView; |
| 10 | + |
| 11 | +import com.omega_r.libs.omegaintentbuilder.OmegaIntentBuilder; |
| 12 | +import com.omega_r.libs.omegaintentbuilder.handlers.ActivityResultCallback; |
| 13 | +import com.omega_r.libs.omegaintentbuilder.handlers.FailCallback; |
| 14 | + |
| 15 | +import org.jetbrains.annotations.NotNull; |
| 16 | +import org.jetbrains.annotations.Nullable; |
| 17 | + |
| 18 | +public class VideoRecordActivity extends BaseActivity implements View.OnClickListener { |
| 19 | + private VideoView videoView; |
| 20 | + |
| 21 | + @Override |
| 22 | + protected void onCreate(Bundle savedInstanceState) { |
| 23 | + super.onCreate(savedInstanceState); |
| 24 | + setContentView(R.layout.activity_video_record); |
| 25 | + videoView = findViewById(R.id.video_view); |
| 26 | + findViewById(R.id.button_open_camera_to_record).setOnClickListener(this); |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public void onClick(View v) { |
| 31 | + OmegaIntentBuilder |
| 32 | + .recordVideo() |
| 33 | + .createIntentHandler(this) |
| 34 | + .failCallback(new FailCallback() { |
| 35 | + @Override |
| 36 | + public void onActivityStartError(@NotNull Exception exc) { |
| 37 | + Toast.makeText(VideoRecordActivity.this, exc.toString(), Toast.LENGTH_SHORT).show(); |
| 38 | + } |
| 39 | + }) |
| 40 | + .startActivityForResult(new ActivityResultCallback() { |
| 41 | + @Override |
| 42 | + public void onActivityResult(int resultCode, @Nullable Intent data) { |
| 43 | + if (resultCode == RESULT_OK) { |
| 44 | + Uri videoUri = data.getData(); |
| 45 | + if (videoUri != null) { |
| 46 | + videoView.setVisibility(View.VISIBLE); |
| 47 | + videoView.setVideoURI(videoUri); |
| 48 | + videoView.start(); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + }); |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments