Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25770] Android: requestThumbnailImagesAtTimes() does not work with remote content

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2018-05-02T18:19:34.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.3.0
ComponentsAndroid
Labelsn/a
ReporterYordan Banev
AssigneeYordan Banev
Created2018-02-12T16:39:26.000+0000
Updated2018-06-11T14:13:53.000+0000

Description

Requesting a thumb from a video payer that has a remote video loaded results in a crash. Test case:
var win = Ti.UI.createWindow({layout:'vertical'}),
    buttonCamera = Ti.UI.createButton({title: "Camera"}),
    buttonGallery = Ti.UI.createButton({title: "Gallery"}),
    buttonLocalURL = Ti.UI.createButton({title: "Local"}),
    buttonRemoteURL = Ti.UI.createButton({title: "Remote"}),
    buttonLayout = Ti.UI.createView({bottom: 20, layout:'horizontal'}),
    slider = Ti.UI.createSlider({top: 30, backgroundColor: 'gray', min: 0, max: 100, width: '100%', touchEnabled: false, enabled: false}),
    videoPlayer = Ti.Media.createVideoPlayer({top: 20, height:'30%', autoplay: false}),
    imageView = Ti.UI.createImageView({top: 20, height:'30%'}),
    updatingThumbnail = false;

buttonLayout.add([buttonCamera, buttonGallery, buttonLocalURL, buttonRemoteURL]);
win.add(videoPlayer);
win.add(imageView);
win.add(slider);
win.add(buttonLayout);
win.open();

slider.addEventListener('change', function(e) {
    if (videoPlayer && e.value > 0 && !updatingThumbnail) {
        updatingThumbnail = true;
        videoPlayer.requestThumbnailImagesAtTimes([e.value], Ti.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
            imageView.image = response.image;
            updatingThumbnail = false;
        });
    }
});

videoPlayer.addEventListener('durationavailable', function() {
    enableGetThumbSlider();
});

buttonCamera.addEventListener('click', recordVideo);

function recordVideo() {
    disableGetThumbSlider();
    var permissionsToRequest = [];
    var cameraPermission = "android.permission.CAMERA";
    var hasCameraPerm = Ti.Android.hasPermission(cameraPermission);
    if (!hasCameraPerm) {
        permissionsToRequest.push(cameraPermission);
    }

    var storagePermission = "android.permission.READ_EXTERNAL_STORAGE";
    var hasStoragePerm = Ti.Android.hasPermission(storagePermission);
    if (!hasStoragePerm) {
        permissionsToRequest.push(storagePermission);
    }

    if(permissionsToRequest.length > 0) {
        Ti.Android.requestPermissions(permissionsToRequest, function (e) {
            if (e.success) {
                showCamera();
            }
        });
    } else {
        showCamera();
    }
}

function showCamera() {
    Ti.Media.showCamera({
        autohide: false,
        animated: false,
        allowEditing: false,
        success:function(event) {
            videoPlayer.url = event.media.nativePath;
        },
        cancel:function() {
            console.log("cancel");
        },
        error:function(error) {
            console.log("error");
            console.log(error);
        },
        mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO],
    });
}

buttonLocalURL.addEventListener("click", function() {
    disableGetThumbSlider();
    videoPlayer.url = 'BigBuckBunny_320x180.mp4';
});

buttonRemoteURL.addEventListener("click", function() {
    disableGetThumbSlider();
    videoPlayer.url = 'http://ve-ep.ember.ltd/assets/media/qa/samplevideo-1280x720-5mb.mp4';
});

buttonGallery.addEventListener("click", function() {
    disableGetThumbSlider();
    var intent = Ti.Android.createIntent({
        action: Ti.Android.ACTION_PICK,
        type: "video/*"
    });
    intent.addCategory(Ti.Android.CATEGORY_DEFAULT);
    win.getActivity().startActivityForResult(intent, function(e) {
        if (e.intent != null) {
            videoPlayer.url = e.intent.data;
        }
    });
});

function disableGetThumbSlider() {
    slider.touchEnabled = false;
    slider.enabled = false;
}

function enableGetThumbSlider() {
    slider.touchEnabled = true;
    slider.enabled = true;
}

Comments

  1. Yordan Banev 2018-02-13

    PR: https://github.com/appcelerator/titanium_mobile/pull/9817
  2. Lokesh Choudhary 2018-05-02

    FR done by [~smohammed], PR merged.
  3. Samir Mohammed 2018-06-11

    Closing ticket. Fix can be seen in SDK Version: 7.3.0.v20180607210411 Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/9817

JSON Source