Created
January 6, 2014 13:27
-
-
Save mitulbhalia/8282889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Titanium.UI.createWindow({ | |
title: 'Video Record', | |
backgroundColor: '#fff' | |
}); | |
var videoUri = null; | |
function startRecording(){ | |
var intent = Titanium.Android.createIntent({ action: 'android.media.action.VIDEO_CAPTURE' }); | |
Titanium.Android.currentActivity.startActivityForResult(intent, function(e) { | |
if (e.error) { | |
Ti.UI.createNotification({ | |
duration: Ti.UI.NOTIFICATION_DURATION_LONG, | |
message: 'Error: ' + e.error | |
}).show(); | |
} else { | |
if (e.resultCode === Titanium.Android.RESULT_OK) { | |
videoUri = e.intent.data; | |
Ti.UI.createNotification({ | |
duration: Ti.UI.NOTIFICATION_DURATION_LONG, | |
message: 'Video captured' | |
}).show(); | |
shareButton.visible = true; | |
saveButton.visible = true; | |
} else { | |
Ti.UI.createNotification({ | |
duration: Ti.UI.NOTIFICATION_DURATION_LONG, | |
message: 'Canceled/Error? code: ' + e.resultCode | |
}).show(); | |
} | |
} | |
}); | |
} | |
function saveVideo(){ | |
var source = Ti.Filesystem.getFile(videoUri); | |
var target = Ti.Filesystem.getFile(<target path>); | |
source.copy(target.nativePath); | |
Ti.UI.createNotification({ | |
duration: Ti.UI.NOTIFICATION_DURATION_LONG, | |
message: 'Saved to: ' + target.nativePath | |
}).show(); | |
} | |
var recordButton = Titanium.UI.createButton({ | |
top: 10, left: 10, right: 10, height: 35, title: 'Record Video' | |
}); | |
recordButton.addEventListener('click', function() { | |
startRecording(); | |
}); | |
win.add(recordButton); | |
var saveButton = Titanium.UI.createButton({ | |
top: 100, left: 10, right: 10, height: 35, | |
title: 'Save Video', visible: false | |
}); | |
saveButton.addEventListener('click', function() { | |
saveVideo(); | |
}); | |
win.add(saveButton); | |
win.open(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment