Created
June 8, 2015 08:10
-
-
Save sharpred/dc2a7f722c8d61c9ea8d to your computer and use it in GitHub Desktop.
save a movie
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 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