Commit d0efdf84 authored by ylwu's avatar ylwu Committed by Gerrit Review System

changed the location clips are stored in camcorder component. Instead

of creating a /Video folder and store it inside, we store the video in
the place where video clips are usually stored using camcorder.

Change-Id: Id2d78897535e579b9ecb69ce85e9aefc79f113bc
parent 5be74dbb
...@@ -29,22 +29,20 @@ import java.util.Date; ...@@ -29,22 +29,20 @@ import java.util.Date;
*/ */
@DesignerComponent(version = YaVersion.CAMCORDER_COMPONENT_VERSION, @DesignerComponent(version = YaVersion.CAMCORDER_COMPONENT_VERSION,
description = "A component to record a video using the device's camcorder." + description = "A component to record a video using the device's camcorder." +
"After the video is recorded, the name of the file on the phone " + "After the video is recorded, the name of the file on the phone " +
"containing the clip is available as an argument to the " + "containing the clip is available as an argument to the " +
"AfterRecording event. The file name can be used, for example, to set " + "AfterRecording event. The file name can be used, for example, to set " +
"the source property of a VideoPlayer component.", "the source property of a VideoPlayer component.",
category = ComponentCategory.MEDIA, category = ComponentCategory.MEDIA,
nonVisible = true, nonVisible = true,
iconName = "images/camcorder.png") iconName = "images/camcorder.png")
@SimpleObject @SimpleObject
public class Camcorder extends AndroidNonvisibleComponent public class Camcorder extends AndroidNonvisibleComponent
implements ActivityResultListener, Component { implements ActivityResultListener, Component {
private static final String CAMCORDER_INTENT = "android.media.action.VIDEO_CAPTURE"; private static final String CAMCORDER_INTENT = "android.media.action.VIDEO_CAPTURE";
private static final String CAMCORDER_OUTPUT = "output";
private final ComponentContainer container; private final ComponentContainer container;
private Uri clipFile;
/* Used to identify the call to startActivityForResult. Will be passed back /* Used to identify the call to startActivityForResult. Will be passed back
into the resultReturned() callback method. */ into the resultReturned() callback method. */
...@@ -65,64 +63,45 @@ public class Camcorder extends AndroidNonvisibleComponent ...@@ -65,64 +63,45 @@ public class Camcorder extends AndroidNonvisibleComponent
*/ */
@SimpleFunction @SimpleFunction
public void RecordVideo() { public void RecordVideo() {
Date date = new Date();
String state = Environment.getExternalStorageState(); String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) { if (Environment.MEDIA_MOUNTED.equals(state)) {
Log.i("CamcorderComponent", "External storage is available and writable"); Log.i("CamcorderComponent", "External storage is available and writable");
clipFile = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
"/Video/app_inventor_" + date.getTime()
+ ".3gp"));
ContentValues values = new ContentValues();
values.put(MediaStore.Video.Media.DATA, clipFile.getPath());
values.put(MediaStore.Video.Media.MIME_TYPE, "clip/3gp");
values.put(MediaStore.Video.Media.TITLE, clipFile.getLastPathSegment());
if (requestCode == 0) { if (requestCode == 0) {
requestCode = form.registerForActivityResult(this); requestCode = form.registerForActivityResult(this);
} }
Uri clipUri = container.$context().getContentResolver().insert(
MediaStore.Video.Media.INTERNAL_CONTENT_URI, values);
Intent intent = new Intent(CAMCORDER_INTENT); Intent intent = new Intent(CAMCORDER_INTENT);
intent.putExtra(CAMCORDER_OUTPUT, clipUri);
container.$context().startActivityForResult(intent, requestCode); container.$context().startActivityForResult(intent, requestCode);
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
form.dispatchErrorOccurredEvent(this, "RecordVideo", form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY); ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY);
} else { } else {
form.dispatchErrorOccurredEvent(this, "RecordVideo", form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE); ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE);
} }
} }
@Override @Override
public void resultReturned(int requestCode, int resultCode, Intent data) { public void resultReturned(int requestCode, int resultCode, Intent data) {
Log.i("CamcorderComponent", Log.i("CamcorderComponent",
"Returning result. Request code = " + requestCode + ", result code = " + resultCode); "Returning result. Request code = " + requestCode + ", result code = " + resultCode);
if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) { if (requestCode == this.requestCode && resultCode == Activity.RESULT_OK) {
File clip = new File(clipFile.getPath()); if (data != null && data.getData() != null) {
if (clip.length() != 0) { Uri tryClipUri = data.getData();
AfterRecording(clipFile.toString()); Log.i("CamcorderComponent", "Calling Camcorder.AfterPicture with clip path "
+ tryClipUri.toString());
AfterRecording(tryClipUri.toString());
} else { } else {
deleteFile(clipFile); // delete empty file Log.i("CamcorderComponent", "Couldn't find a clip file from the Camcorder result");
// see if something useful got returned in the data form.dispatchErrorOccurredEvent(this, "TakeVideo",
if (data != null && data.getData() != null) { ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
Uri tryClipUri = data.getData();
Log.i("CamcorderComponent", "Calling Camcorder.AfterPicture with clip path "
+ tryClipUri.toString());
AfterRecording(tryClipUri.toString());
} else {
Log.i("CamcorderComponent", "Couldn't find a clip file from the Camcorder result");
form.dispatchErrorOccurredEvent(this, "TakeVideo",
ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
}
} }
} else { } else {
// delete empty file Log.i("CamcorderComponent", "No clip filed rerturn; request failed");
deleteFile(clipFile); form.dispatchErrorOccurredEvent(this, "TakeVideo",
ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
} }
} }
...@@ -136,7 +115,7 @@ public class Camcorder extends AndroidNonvisibleComponent ...@@ -136,7 +115,7 @@ public class Camcorder extends AndroidNonvisibleComponent
} }
} catch (SecurityException e) { } catch (SecurityException e) {
Log.i("CamcorderComponent", "Got security exception trying to delete file " Log.i("CamcorderComponent", "Got security exception trying to delete file "
+ fileUri.toString()); + fileUri.toString());
} }
} }
...@@ -145,7 +124,7 @@ public class Camcorder extends AndroidNonvisibleComponent ...@@ -145,7 +124,7 @@ public class Camcorder extends AndroidNonvisibleComponent
* the stored picture. * the stored picture.
*/ */
@SimpleEvent @SimpleEvent
public void AfterRecording(String clip) { public void AfterRecording(String clip) {
EventDispatcher.dispatchEvent(this, "AfterRecording", clip); EventDispatcher.dispatchEvent(this, "AfterRecording", clip);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment