androidtitaniumappceleratortitanium-mobiletitanium-android

in Titanium, how to take a thumbnail from video in android?


I'm trying to get a thumbnail image from a video player that I set the Url when I choose a video from gallery or capture a video, so this my code in controller:-

var intent = Titanium.Android.createIntent({
    action: Ti.Android.ACTION_PICK,
    type : "video/*"
});
intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
var curActivity =  $.createPost.getActivity();

curActivity.startActivityForResult(intent, function(event) {
    if (event.resultCode == Ti.Android.RESULT_OK) {
        if (event.intent.data != null) {
            // If everything went OK, save a reference to the video URI
            Ti.API.info('here '+ event.intent.data);
            Ti.API.info('video: '+ event.intent);
            var videoPath = event.intent.data;
            video = Ti.Filesystem.getFile(videoPath);

            $[e.source.fileView].setUrl(event.intent.data);
            // $[e.source.fileView].setMedia(file);
            $[e.source.fileView].setVisible(true);
            $[e.source.removeBtn].setVisible(true);

            $.video.requestThumbnailImagesAtTimes([0,1,2,6,12], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (response) {
                alert('text');
                Ti.API.info("Thumbnail callback called, success = " + response.success);
                Ti.API.info("Thumbnail callback called, time = " + response.time);
                Ti.API.info("Thumbnail callback called, code = " + response.code);
                if(response.success) {
                    videoThumb = response.image;
                }
            });
        }
        else {
            Ti.API.error('Could not retrieve media URL!');
        }
    }
    else if (event.resultCode == Ti.Android.RESULT_CANCELED) {
        Ti.API.trace('User cancelled video capture session.');
    }
    else {
        Ti.API.error('Could not record video!');
    }
});

I get the video and it appears in the video player ($.video) but I can't get the thumbnail at all. this code works just fine in IOS

            $.video.requestThumbnailImagesAtTimes([0,1,2,6,12], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (response) {
                alert('text');
                Ti.API.info("Thumbnail callback called, success = " + response.success);
                Ti.API.info("Thumbnail callback called, time = " + response.time);
                Ti.API.info("Thumbnail callback called, code = " + response.code);
                if(response.success) {
                    videoThumb = response.image;
                }
            });

but not in android.


Solution

  • It appears that at this time you cannot do this: it's broken. Here's the Jira ticket for the issue: Android: Get image frames at times out of local video

    It indicates that it's fixed in 6.1.0. Apparently now you can do this with a remote video, so if that fits your workflow you might be able to accomplish it.

    Does this answer your question?