Recorded video won't show on viewVideo - java

I just need help on my codes, I'm using Android Studio. Everything is working fine but the recorded video won't show in viewVideo on my layout.
Here's the code:
public class MainActivity extends AppCompatActivity {
static final int REQUEST_VIDEO_CAPTURE = 1;
VideoView resultvideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button click = (Button)findViewById(R.id.videorec);
resultvideo = (VideoView)findViewById(R.id.videoView);
}
public void dispatchTakeVideoIntent(View v) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
resultvideo.setVideoURI(videoUri);
}
}
}

Uri videoUri = data.getData();
resultvideo.setVideoURI(videoUri);
// start call missing
resultvideo.start();

Related

childName cannot be null or empty with camera in Android Studio

When I run it, I get an error saying that childName cannot be null. The variable "data" is getting null when taking the photo and I don't know how to fix it.
This is my code.
public class TakePhoto extends AppCompatActivity {
private Button btnPhoto;
private ImageView mImageView;
private static final int CAMERA_REQUEST_CODE = 1;
private StorageReference storage;
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
String fecha = df.format(c.getTime());
private ProgressDialog progress;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_photo);
storage = FirebaseStorage.getInstance().getReference();
btnPhoto = (Button) findViewById(R.id.buttonCamera2);
mImageView = (ImageView) findViewById(R.id.fotoFinal);
progress = new ProgressDialog(this);
btnPhoto.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST_CODE);
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, #Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK){
Uri uri = data.getData();
StorageReference filepath = storage.child(getIntent().getStringExtra("dato")).child(fecha + " " + uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
#Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(TakePhoto.this, "Subiendo...", Toast.LENGTH_LONG).show();
}
});
}
}
}

Share image taking from Camera

I am developing an app which takes a picture with the camera and allows the user to share it. But the share intent isn't working. I have checked but none are working on my device. I am running the app on an Android 6.0 marshmallow tablet.
Here is my code
public class SharePic extends Activity {
static final int REQUEST_IMAGE_CAPTURE = 1;
ImageView picView;
Button shareBtn;
Bitmap imageBitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share_pic);
picView = (ImageView) findViewById(R.id.picView);
shareBtn = (Button) findViewById(R.id.shareBtn);
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
imageBitmap = (Bitmap) extras.get("data");
picView.setImageBitmap(imageBitmap);
}
}
public void share(View view){
String bitmapPath = MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap,"title", null);
Uri bitmapUri = Uri.parse(bitmapPath);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
startActivity(Intent.createChooser(intent , "Share"));
}
}
Any help?
So, when is the share button being called.
I guess you might have to set event listener setOnClickListener on share button click in case you haven't set it in the XML
shareBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
share(v);
}
});

Play button on ViewVideo

I would like to know how to put a play button on the viewVideo on my layout. Also do I have to put something on my layout for it to work?
Here's my code:
public class MainActivity extends AppCompatActivity {
static final int REQUEST_VIDEO_CAPTURE = 1;
VideoView resultvideo;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button click = (Button)findViewById(R.id.videorec);
resultvideo = (VideoView)findViewById(R.id.videoView);
}
public void dispatchTakeVideoIntent(View v) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
resultvideo.setVideoURI(videoUri);
resultvideo.start();
}
}
}
Use FrameLayout.
Specify a drawable you can see in FrameLayout children. and use Foreground Drawable to draw the button with a drawable:
myFrameLayout.setForegroundDrawable(myPlayDrawable);

Play videoView on another activity

I have an ImageButton which plays the video I recorded. Everything works fine but the thing is I want to play the recorded video(resultvideo) on another activity. I'm new to Android Dev. could someone teach me how to do that, thanks!
Here's my code:
public class MainActivity extends AppCompatActivity {
ImageButton imageButton;
static final int REQUEST_VIDEO_CAPTURE = 1;
VideoView resultvideo;
MediaController mediacontroller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultvideo = (VideoView)findViewById(R.id.videoView);
mediacontroller = new MediaController(MainActivity.this);
mediacontroller.setAnchorView(resultvideo);
resultvideo.setMediaController(mediacontroller);
Button click = (Button)findViewById(R.id.buttonRecord);
resultvideo = (VideoView)findViewById(R.id.videoView);
}
public void dispatchTakeVideoIntent(View v) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
resultvideo.setVideoURI(videoUri);
resultvideo.pause();
}
imageButton = (ImageButton) findViewById(R.id.imageButton);
{
imageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Main2Activity.class));
resultvideo.start();
}
});
}
}
}
You can send Uri of video via Intent to another activity
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("VIDEO_URI", videoUri.toString());
startActivity(intent);
And then in Main2Activity in onCreate method get videoUri like this:
String uri = getIntent().getStringExtra("VIDEO_URI");
Uri videoUri = Uri.parse(uri);

ImageButton Disappearing

I have a VideoView and an ImageButton(Play Button for the video) where I record a video and play it using the ImageButton. Everything works fine but when I try to record again another video. The ImageButton disappears.
Here's my code:
public class MainActivity extends AppCompatActivity {
ImageButton imageButton;
static final int REQUEST_VIDEO_CAPTURE = 1;
VideoView resultvideo;
MediaController mediacontroller;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultvideo = (VideoView)findViewById(R.id.videoView);
mediacontroller = new MediaController(MainActivity.this);
mediacontroller.setAnchorView(resultvideo);
resultvideo.setMediaController(mediacontroller);
Button click = (Button)findViewById(R.id.buttonRecord);
resultvideo = (VideoView)findViewById(R.id.videoView);
}
public void dispatchTakeVideoIntent(View v) {
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
Uri videoUri = data.getData();
resultvideo.setVideoURI(videoUri);
resultvideo.pause();
}
imageButton = (ImageButton) findViewById(R.id.imageButton);
{
imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
resultvideo.start();
mediacontroller.show();
imageButton.setVisibility(View.GONE);
}
});
}
}
}
Not sure why you expect other behaviour as the only setVisibility() call on that button you got in your code is:
imageButton.setVisibility(View.GONE);
so either remove that line or make button visible again when needed by calling
imageButton.setVisibility(View.VISIBLE);
EDIT
How do I make it disappear while the video is playing and call it back when the video is finish
Use MediaPlayer's OnCompletionListener

Categories