1

I am fairly new to android studio and developing with android. I have been trying this for months now, I need to record and save a video using Google Glass. The code that I currently have follows. This is code inspired from https://developers.google.com/glass/develop/gdk/camera#images

When I run this process, the video will start recording and then when the recording is stopped, it will give me the option "tap to accept" When I tap, nothing happens. I understand this is because my method "processVideoWhenReady" does absolutely nothing.

I would like to know if anyone could help me with what I should include in that method to save the video and allow it to be viewed by the user within my application.

Any literature or websites that have useful information about developing for Google Glass would also be a huge help if possible. Google's documentation doesn't seem very helpful to me and very limited.

import android.app.Activity;
import android.graphics.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.content.Intent;
import android.os.FileObserver;
import android.provider.MediaStore;
import android.util.Log;
import android.widget.VideoView;

import com.google.android.glass.content.Intents;
import com.google.android.glass.widget.CardBuilder;

import java.io.File;
import java.io.IOException;


public class RecordActivity extends Activity {
  private static final int CAMERA_VID_REQUEST = 1337;
  static final int REQUEST_VIDEO_CAPTURE = 1;
  public VideoView mVideoView;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      //setContentView(R.layout.activity_record);
      takeVideo();
  }

  private void takeVideo(){
      Intent startVideo = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

      if (startVideo.resolveActivity(getPackageManager()) != null){
          startActivityForResult(startVideo, REQUEST_VIDEO_CAPTURE);
      }
      //RecordActivity.this.startActivityForResult(startVideo, CAMERA_VID_REQUEST);

  }

  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data){
      //System.out.println("Entered onActivityResult() method");
      String a = getIntent().getStringExtra("record");
      System.out.println(a);
      if(requestCode == CAMERA_VID_REQUEST && resultCode == RESULT_OK) {
          //System.out.println("Result Okay");
          Uri videoUri = data.getData();
          mVideoView.setVideoURI(videoUri);
          String videoPath = data.getStringExtra(Intents.EXTRA_VIDEO_FILE_PATH);
          processVideoWhenReady(videoPath);
      }
      super.onActivityResult(requestCode, resultCode, data);
  }

  protected void processVideoWhenReady(final String videoPath){
      final File videoFile = new File(videoPath);
      if (videoFile.exists()){
          //Process Video

    }
    else {
        final File parentDirectory = videoFile.getParentFile();
        FileObserver observer = new FileObserver(parentDirectory.getPath(), FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
            private boolean isFileWritten;

            @Override
            public void onEvent(int event, String path) {
                if (!isFileWritten) {
                    //make sure file was created in directory expected
                    File affectedFile = new File(parentDirectory, path);
                    isFileWritten = affectedFile.equals(videoFile);

                    if (isFileWritten) {
                        stopWatching();

                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                processVideoWhenReady(videoPath);
                            }
                        });
                    }
                }

            }
        };

        observer.startWatching();
    }
}

}

Adam
  • 1,489
  • 2
  • 10
  • 11

0 Answers0