@ShortName("VideoRecordApp")
@Events(values={"RecordComplete (Success As Boolean)"})
public class VideoRecordApp {
private IOnActivityResult ion;
private String eventName;
/**
* Initializes the object and sets the sub that will handle the event.
*/
public void Initialize(String EventName) {
this.eventName = EventName.toLowerCase(BA.cul);
}
/**
* Calls the recording application.
*Dir and FileName set the output file location.
*/
public void Record(final BA ba, final String Dir, final String FileName) {
Record2(ba, Dir, FileName, -1);
}
/**
* Calls the recording application.
*Dir and FileName set the output file location.
MaxLengthSeconds - Sets the maximum duration (in seconds).
*/
public void Record2(final BA ba, final String Dir, final String FileName, final int MaxLengthSeconds) {
if (eventName == null)
throw new RuntimeException("You should first call Initialize.");
ion = new IOnActivityResult() {
@Override
public void ResultArrived(int resultCode, final Intent intent) {
ion = null;
boolean success = resultCode == Activity.RESULT_OK;
if (success) {
ba.submitRunnable(new Runnable() {
@Override
public void run() {
try {
String uri = intent.getData().toString();
if (uri.startsWith("file://")) {
if (uri.equals(Uri.parse("file://" + File.Combine(Dir, FileName)).toString()) == false) {
File.Copy("", uri.substring(7), Dir, FileName);
}
} else {
File.Copy(File.ContentDir, intent.getData().toString(), Dir, FileName);
BA.applicationContext.getContentResolver().delete(Uri.parse(intent.getData().toString()), null, null);
}
ba.raiseEventFromDifferentThread(VideoRecordApp.this, null, 0, eventName + "_recordcomplete", false, new Object[] {true});
} catch (Exception e) {
e.printStackTrace();
ba.setLastException(e);
ba.raiseEventFromDifferentThread(VideoRecordApp.this, null, 0, eventName + "_recordcomplete", false, new Object[] {false});
}
}
}, null, 0);
}
else {
ba.raiseEvent(VideoRecordApp.this, eventName + "_recordcomplete", false);
}
}
};
Intent i = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
i.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
if (Build.VERSION.SDK_INT >= 18) {
String dir = Dir;
if (Dir != File.getDirRootExternal() && Dir != File.getDirDefaultExternal())
dir = File.getDirDefaultExternal();
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.parse("file://" + File.Combine(dir, FileName)));
}
if (MaxLengthSeconds > 0)
i.putExtra("android.intent.extra.durationLimit", MaxLengthSeconds);
ba.startActivityForResult(ion, i);
}
}