2

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.

Rene Pot
  • 24,681
  • 7
  • 68
  • 92
mohamed al-ashry
  • 251
  • 6
  • 17

1 Answers1

2

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?

Steven H
  • 357
  • 2
  • 9
  • Here's the PR https://github.com/appcelerator/titanium_mobile/pull/8830 – Steven H Apr 19 '17 at 23:38
  • It didn't work with remote or the newer SDK for me. My solution was to use [ffmpeg Android Titanium module](https://github.com/badoque/titanium-ffmpeg-android-wrapper) and do it with the command to generate a thumbnail. Here's the command, though has to be done in the Ti way `ffmpeg -i input.flv -ss 00:00:14.435 -vframes 1 out.png` – Steven H Apr 22 '17 at 16:17
  • i tried with titanium sdk 6.1.0 and it works for local video files also. http://builds.appcelerator.com/#6_1_X – mohamed al-ashry Apr 23 '17 at 15:12
  • My prior approach has some cavaets. Could you tell me exactly which SDK you are using from that link? This didn't work for me: 6.1.0.v20170417190415 – Steven H Apr 28 '17 at 03:37