Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25638] iOS: Callback of requestThumbnailImagesAtTimes is not fired

GitHub Issuen/a
TypeBug
PriorityCritical
StatusResolved
ResolutionCannot Reproduce
Resolution Date2018-01-10T14:44:30.000+0000
Affected Version/sRelease 7.0.0
Fix Version/sn/a
ComponentsiOS
Labelsvideo
ReporterMohamad Alhajj
AssigneeVijay Singh
Created2017-12-28T16:03:50.000+0000
Updated2018-01-10T14:45:18.000+0000

Description

I'm trying to get video thumbnail using the below snippet code, but requestThumbnailImagesAtTimes doesn't call the callback at all on iOS, while it works on android. requestThumbnailImagesAtTimes, is used on a local video, I tried bot to set the URL, or media but doesn't seem to work.

function openIOSVideoGallery() {
    Titanium.Media.openPhotoGallery({
        success: function (e) {
            if (e.success && e.mediaType == Titanium.Media.MEDIA_TYPE_VIDEO)
                getVideoThumbnail(e.media).then(function (success) {
                    //On Thumbnail Success
                }).catch(function (error) {
                    //On Thumbnail Error
                });
        },
        cancel: function (e) {
            console.log(e);
        },
        error: function (e) {
            console.log(e);
        },
        mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO]
    });
}

function getVideoThumbnail(video) {
    return new Promise(function (resolve, reject) {
            Titanium.Media.createVideoPlayer({
                height: dpToPixel(100),
                url: video.nativePath,
                scalingMode: Ti.Media.VIDEO_SCALING_ASPECT_FILL,
                width: dpToPixel(100)
            }).requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (e) {
                if (e.success) {
                    resolve({
                        thumbnail: e.image,
                        media: video
                    });
                } else {
                    reject({
                        error: e.error,
                        media: video
                    });
                }
            });
    });
}

Comments

  1. Hans Knöchel 2017-12-30

    [~malhajj] I think your attached test-case belongs to a different ticket? I moved it to TIMOB for further investigation.
  2. Mohamad Alhajj 2017-12-30

    Hi Hans, Yes your right you can remove the attached test case, since it belongs to another ticket. Thanks, Sent from JIRA Mobile
  3. Hans Knöchel 2018-01-01

    Example test-case:
       /**
        * This file is used to validate iOS test-cases. It is ran using the Xcode
        * project in titanium_mobile/iphone/iphone/Titanium.xcodeproj.
        *
        * Change the below code to fit your use-case. By default, it included a button
        * to trigger a log that is displayed in the Xcode console.
        */
       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
             });
           }
         });
       }
       
    Weirdly, it calls the callback as expected but then errors when trying to set an image to display the result. Probably [~vijaysingh] will know some more insights here!
  4. Vijay Singh 2018-01-02

    [~hknoechel] [~malhajj] The test case, which [~hknoechel] has attached, has a typo inside selectVideo() function. Rather e.thumbnail it should be _e.thumbnail. Please find the updated section inside selectVideo() function -
       getVideoThumbnail(e.media, function(_e) {
                 if (_e.error) {
                   alert('Error: ' + _e.error);
                 } else {
                   win.add(Ti.UI.createImageView({
                     image: _e.thumbnail
                   }));
                 }
               });
       
    Now it will work fine. Let me know if you are facing any other issue. Thanks!
  5. Hans Knöchel 2018-01-02

    Ohhh, of course, you are right! Holiday is still in my head. [~malhajj] Let us know your feedback!
  6. Hans Knöchel 2018-01-03

    [~vijaysingh] May this be a kroll-thread issue? [~malhajj] Please give us some feedback, thanks!
  7. Vijay Singh 2018-01-04

    [~hknoechel] I have verified on kroll-thread also. Its working fine. Let's wait for [~malhajj]'s feedback.
  8. Hans Knöchel 2018-01-10

    [~malhajj] One more ping. We are not able to reproduce it and all test-cases pass. Please let us know by end of the day or we need to resolve it as Cannot Reproduce for now. *EDIT*: Resolving as Cannot Reproduce due to our test results and no activity.

JSON Source