Skip to content

Instantly share code, notes, and snippets.

@sharpred
Created June 8, 2015 08:10
Show Gist options
  • Save sharpred/dc2a7f722c8d61c9ea8d to your computer and use it in GitHub Desktop.
Save sharpred/dc2a7f722c8d61c9ea8d to your computer and use it in GitHub Desktop.
save a movie
var movie = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'mymovie.mov');
var thumb = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'mymoviethumb.jpg');
Titanium.Media.showCamera({
success : function(event) {
var video = event.media;
if (movie.exists()) {
movie.deleteFile();
}
movie.write(video);
},
cancel : function() {
console.log("you cancelled the recording");
},
error : function(error) {
// create alert
var a = Titanium.UI.createAlertDialog({
title : 'Video'
});
// set message
if (error.code == Titanium.Media.NO_VIDEO) {
a.setMessage('Device does not have video recording capabilities');
} else {
a.setMessage('Unexpected error: ' + error.code);
}
// show alert
a.show();
},
mediaTypes : Titanium.Media.MEDIA_TYPE_VIDEO,
videoQuality : Titanium.Media.QUALITY_HIGH
});
var activeMovie = Titanium.Media.createVideoPlayer({
backgroundColor : '#111',
mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
media : movie // note you can use either contentURL to nativePath or the file object
});
activeMovie.requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(e) {
if (e.success) {
if (thumb.exists()) {
thumb.deleteFile();
}
if (e.image) {
thumb.write(e.image);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment