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;
*/
@DesignerComponent(version = YaVersion.CAMCORDER_COMPONENT_VERSION,
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 " +
"containing the clip is available as an argument to the " +
"AfterRecording event. The file name can be used, for example, to set " +
"the source property of a VideoPlayer component.",
category = ComponentCategory.MEDIA,
nonVisible = true,
iconName = "images/camcorder.png")
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 " +
"containing the clip is available as an argument to the " +
"AfterRecording event. The file name can be used, for example, to set " +
"the source property of a VideoPlayer component.",
category = ComponentCategory.MEDIA,
nonVisible = true,
iconName = "images/camcorder.png")
@SimpleObject
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_OUTPUT = "output";
private final ComponentContainer container;
private Uri clipFile;
/* Used to identify the call to startActivityForResult. Will be passed back
into the resultReturned() callback method. */
......@@ -65,64 +63,45 @@ public class Camcorder extends AndroidNonvisibleComponent
*/
@SimpleFunction
public void RecordVideo() {
Date date = new Date();
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
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) {
requestCode = form.registerForActivityResult(this);
}
Uri clipUri = container.$context().getContentResolver().insert(
MediaStore.Video.Media.INTERNAL_CONTENT_URI, values);
Intent intent = new Intent(CAMCORDER_INTENT);
intent.putExtra(CAMCORDER_OUTPUT, clipUri);
container.$context().startActivityForResult(intent, requestCode);
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY);
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_READONLY);
} else {
form.dispatchErrorOccurredEvent(this, "RecordVideo",
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE);
ErrorMessages.ERROR_MEDIA_EXTERNAL_STORAGE_NOT_AVAILABLE);
}
}
@Override
public void resultReturned(int requestCode, int resultCode, Intent data) {
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) {
File clip = new File(clipFile.getPath());
if (clip.length() != 0) {
AfterRecording(clipFile.toString());
if (data != null && data.getData() != null) {
Uri tryClipUri = data.getData();
Log.i("CamcorderComponent", "Calling Camcorder.AfterPicture with clip path "
+ tryClipUri.toString());
AfterRecording(tryClipUri.toString());
} else {
deleteFile(clipFile); // delete empty file
// see if something useful got returned in the data
if (data != null && data.getData() != null) {
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);
}
Log.i("CamcorderComponent", "Couldn't find a clip file from the Camcorder result");
form.dispatchErrorOccurredEvent(this, "TakeVideo",
ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
}
} else {
// delete empty file
deleteFile(clipFile);
Log.i("CamcorderComponent", "No clip filed rerturn; request failed");
form.dispatchErrorOccurredEvent(this, "TakeVideo",
ErrorMessages.ERROR_CAMCORDER_NO_CLIP_RETURNED);
}
}
......@@ -136,7 +115,7 @@ public class Camcorder extends AndroidNonvisibleComponent
}
} catch (SecurityException e) {
Log.i("CamcorderComponent", "Got security exception trying to delete file "
+ fileUri.toString());
+ fileUri.toString());
}
}
......@@ -145,7 +124,7 @@ public class Camcorder extends AndroidNonvisibleComponent
* the stored picture.
*/
@SimpleEvent
public void AfterRecording(String clip) {
public void AfterRecording(String 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