Skip to content

Instantly share code, notes, and snippets.

@exclusiveTanim
Created December 17, 2019 15:23
Show Gist options
  • Save exclusiveTanim/e66ab40c8f42d5ee3fee812704410f26 to your computer and use it in GitHub Desktop.
Save exclusiveTanim/e66ab40c8f42d5ee3fee812704410f26 to your computer and use it in GitHub Desktop.
Thumbnail
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var btn = Ti.UI.createButton({
title: 'Select Video + Generate Thumbnail'
});
btn.addEventListener('click', selectVideo);
win.add(btn);
win.open();
function selectVideo() {
Titanium.Media.openPhotoGallery({
success: function(e) {
if (e.mediaType == Titanium.Media.MEDIA_TYPE_VIDEO) {
getVideoThumbnail(e.media, function(_e) {
if (e.error) {
alert('Error: ' + e.error);
} else {
win.add(Ti.UI.createImageView({
image: e.thumbnail
}));
}
});
}
},
cancel: function(e) {
console.log(e);
},
error: function(e) {
console.log(e);
},
mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO]
});
}
function getVideoThumbnail(video, cb) {
var player = Titanium.Media.createVideoPlayer({
height: 100,
url: video.nativePath,
scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FILL,
width: 100
})
player.requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(e) {
if (e.success) {
cb({
thumbnail: e.image,
media: video
});
} else {
cb({
error: e.error,
media: video
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment