Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25020] Android: requestThumbnailImagesAtTimes causes a crash

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2017-08-23T09:41:53.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.2.0
Componentsn/a
Labelsandroid, regression
ReporterZakhar Zhuravlev
AssigneeYordan Banev
Created2017-07-16T13:29:34.000+0000
Updated2018-02-12T16:39:27.000+0000

Description

*index.js:*
var button = Ti.UI.createButton({
    title: "record"
});

button.addEventListener('click', recordVideo);

$.win.add(button);
$.win.open();

function recordVideo() {
    var permissionsToRequest = [];

    var audioPermission = "android.permission.RECORD_AUDIO";
    var hasAudioPerm = Ti.Android.hasPermission(audioPermission);
    if (!hasAudioPerm) {
        permissionsToRequest.push(audioPermission);
    }

    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) {
            var movie = Titanium.Media.createVideoPlayer({
                url:event.media.nativePath,
                backgroundColor:'#111',
                mediaControlStyle: Titanium.Media.VIDEO_CONTROL_EMBEDDED,
                scalingMode:Titanium.Media.VIDEO_SCALING_ASPECT_FILL,
                width:300,
                height:300,
            });
            $.win.add(movie);

            movie.addEventListener('durationavailable', function() {
                movie.requestThumbnailImagesAtTimes([1], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(response) {
                    Ti.API.info("Thumbnail callback called, success = " + response.success);
                    console.log(response);
                    if(response.success) {

                    }
                });
            });
        },
        cancel:function() {
            console.log("cancel");
        },
        error:function(error) {
            console.log("error");
            console.log(error);
        },
        mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO],
    });
}
I'm getting this exception:
[WARN]  W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.database.Cursor.moveToNext()' on a null object reference
[WARN]  W/System.err:   at org.appcelerator.titanium.io.TitaniumBlob.init(TitaniumBlob.java:84)
[WARN]  W/System.err:   at org.appcelerator.titanium.io.TitaniumBlob.<init>(TitaniumBlob.java:33)
[WARN]  W/System.err:   at ti.modules.titanium.media.VideoPlayerProxy.requestThumbnailImagesAtTimes(VideoPlayerProxy.java:722)
[WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
[WARN]  W/System.err:   at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
[WARN]  W/System.err:   at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:872)
[WARN]  W/System.err:   at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1095)
[WARN]  W/System.err:   at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:360)
[WARN]  W/System.err:   at ti.modules.titanium.media.VideoPlayerProxy.handleMessage(VideoPlayerProxy.java:395)
[WARN]  W/System.err:   at android.os.Handler.dispatchMessage(Handler.java:98)
[WARN]  W/System.err:   at android.os.Looper.loop(Looper.java:148)
[WARN]  W/System.err:   at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:118)

Comments

  1. Yordan Banev 2017-07-25

    PR: https://github.com/appcelerator/titanium_mobile/pull/9245
  2. Samir Mohammed 2017-08-22

    [~ybanev] Master is merged, waiting for 6_2_X back-port.
  3. Yordan Banev 2017-08-23

    6_2_X: https://github.com/appcelerator/titanium_mobile/pull/9347
  4. Samir Mohammed 2017-08-24

    Verified fix in SDK Version: 6.2.0.v20170824074531 and SDK Version: 7.0.0.v20170823165814 Test and other information can be found at: Master: https://github.com/appcelerator/titanium_mobile/pull/9245 6_2_X: https://github.com/appcelerator/titanium_mobile/pull/9347
  5. Fabian Martinez 2018-02-07

    This bug has returned on SDK 7.0.1.GA. I'm receiving the same error when trying to create a thumbnail from a videoPlayer on android. It is working on iOS.
  6. Yordan Banev 2018-02-08

    [~inzori] I am not able to reproduce the problem. Would be able to provide a code sample/project which does and information about the device you are using?
  7. Fabian Martinez 2018-02-08

    Hi,
  8. Fabian Martinez 2018-02-08

    Hi, this is the code in index.js: function doClick(e) { var auxVideoPlayer = Ti.Media.createVideoPlayer({ autoplay: false, url: 'http://ve-ep.ember.ltd/assets/media/qa/samplevideo-1280x720-5mb.mp4', height: 200, width: 300, scalingMode: Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL }); $.videoWrapper.add(auxVideoPlayer); auxVideoPlayer.requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (e) { console.log('requested video thumbnail'); console.log(e); if (e.success) { var image = Ti.UI.createImageView({ top: 0, height: 200, width: 300, image: e.image }); svView.add(image); } //auxVideoPlayer = null; //$.videoWrapper.removeAllChildren(); }); $.imageContainer.add(svView); } $.index.open(); Index.tss: ".container": { backgroundColor:"white", layout: 'vertical' } "Label": { width: Ti.UI.SIZE, height: Ti.UI.SIZE, color: "#000", top: 10 } "#label": { font: { fontSize: 12 } } "#imageContainer": { top: 10, touchEnabled: false, } "#videoWrapper": { visible: true, top: 10, height: Ti.UI.SIZE, width: Ti.UI.SIZE } Index.xml The error I get is this, it isn't creating the thumb but the video is playable: [WARN] W/System.err: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.database.Cursor.moveToNext()' on a null object reference [WARN] W/System.err: at org.appcelerator.titanium.io.TitaniumBlob.init(TitaniumBlob.java:84) [WARN] W/System.err: at org.appcelerator.titanium.io.TitaniumBlob.(TitaniumBlob.java:33) [WARN] W/System.err: at ti.modules.titanium.media.VideoPlayerProxy.requestThumbnailImagesAtTimes(VideoPlayerProxy.java:755) [WARN] W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method) [WARN] W/System.err: at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62) [WARN] W/System.err: at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936) [WARN] W/System.err: at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159) [WARN] W/System.err: at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:363) [WARN] W/System.err: at android.os.Handler.dispatchMessage(Handler.java:98) [WARN] W/System.err: at android.os.Looper.loop(Looper.java:154) [WARN] W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6077) [WARN] W/System.err: at java.lang.reflect.Method.invoke(Native Method) [WARN] W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) [WARN] W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755) [ERROR] TiExceptionHandler: (main) [5511,5511] ----- Titanium Javascript Runtime Error ----- [ERROR] TiExceptionHandler: (main) [0,5511] - In /alloy/controllers/index.js:71,18 [ERROR] TiExceptionHandler: (main) [0,5511] - Message: Uncaught Attempt to invoke interface method 'boolean android.database.Cursor.moveToNext()' on a null object reference [ERROR] TiExceptionHandler: (main) [0,5511] - Source: auxVideoPlayer.requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (e) { [ERROR] V8Exception: Exception occurred at /alloy/controllers/index.js:71: Uncaught Attempt to invoke interface method 'boolean android.database.Cursor.moveToNext()' on a null object reference [ERROR] V8Exception: Attempt to invoke interface method 'boolean android.database.Cursor.moveToNext()' on a null object reference [WARN] MediaPlayer: Couldn't open http://ve-ep.ember.ltd/assets/media/qa/samplevideo-1280x720-5mb.mp4: java.io.FileNotFoundException: No content provider: http://ve-ep.ember.ltd/assets/media/qa/samplevideo-1280x720-5mb.mp4
  9. Fabian Martinez 2018-02-08

    Sorry for the bad code sent. This is the correct index.js. Works on iOS but not android. function doClick(e) { var svView = Ti.UI.createView({ top: 0, height: 200, width: 300 }); var auxVideoPlayer = Ti.Media.createVideoPlayer({ autoplay: false, url: 'http://ve-ep.ember.ltd/assets/media/qa/samplevideo-1280x720-5mb.mp4', height: 200, width: 300, scalingMode: Ti.Media.VIDEO_SCALING_RESIZE_ASPECT_FILL }); $.videoWrapper.add(auxVideoPlayer); auxVideoPlayer.requestThumbnailImagesAtTimes([0], Titanium.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function (e) { console.log('requested video thumbnail'); console.log(e); if (e.success) { var image = Ti.UI.createImageView({ top: 0, height: 200, width: 300, image: e.image }); svView.add(image); } //auxVideoPlayer = null; //$.videoWrapper.removeAllChildren(); }); $.imageContainer.add(svView); } $.index.open();
  10. Yordan Banev 2018-02-09

    Thank you for the sample. I was able to reproduce the issue.

JSON Source