Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Created July 10, 2012 17:46
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save tzmartin/3085036 to your computer and use it in GitHub Desktop.
Save tzmartin/3085036 to your computer and use it in GitHub Desktop.
Create Thumbnail Image From Video File, Titanium Mobile
/**
Create Thumbnail of Video File
This snippet captures a thumbnail JPG image, based on a frame @ 2 second time-lapse.
Titanium Mobile
*/
var movie = Titanium.Media.createVideoPlayer({
contentURL:FILENAME,
backgroundColor:'#111',
movieControlStyle: Titanium.Media.VIDEO_CONTROL_EMBEDDED,
scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
width:70,
height:70
});
var thumbBlob = movie.thumbnailImageAtTime(2.0, Titanium.Media.VIDEO_TIME_OPTION_EXACT);
var thumbFile = Titanium.Filesystem.applicationDataDirectory + "/media"+index+"_"+timestamp+".jpg";
var thumb = Titanium.Filesystem.getFile(thumbFile);
thumb.write( thumbBlob );
@adammagana
Copy link

Tried creating a thumbnail from a local video using the following:

var player = Titanium.Media.createVideoPlayer({
    height: 172,
    media: video,
    scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FILL,
    width: 276
});

var imageBlob = player.thumbnailImageAtTime(1.0, Ti.Media.VIDEO_TIME_OPTION_EXACT);

However, the image blob that is returned from thumbnailImageAtTime has a width of 0 and a height of 0. The mime type of the blob says it is in fact a jpeg so I'm not quite sure what could be wrong. If you have any insight it would be much appreciated!

@Espiritha
Copy link

Yss... I have the same issue.. i want thumbnail image for android.

@tzmartin
Copy link
Author

@Espiritha Try using the async method requestThumbnailImagesAtTimes( times, option, callback ), which supports iOS, Android.

@raefa
Copy link

raefa commented Dec 13, 2016

Did anyone find a solution to this? I am finding that if I record a video and then use requestThumbnailImagesAtTimes it will not get into the callback. It will if it is a remote URL. I have tried copying the file to a temp directory but that did not help.

@ashishsharma123
Copy link

ashishsharma123 commented Dec 30, 2016

This Worked for Me. Try this....
videoPlayer.requestThumbnailImagesAtTimes([0],Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME,setBackgroundImage);

//Callback for thumbnail image
function setBackgroundImage(e){
videoPlayer.backgroundImage = e.image;
//By e.image you get thumbnail image.
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment