Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Feb 14, 2018

Conversation

ypbnv
Copy link
Contributor

@ypbnv ypbnv commented Feb 12, 2018

JIRA: https://jira.appcelerator.org/browse/TIMOB-25770

Description:
Fix requestThumbnailAtTimes() for remote content loaded in the VideoPlayer. This change affects loading thumbs for all kind of sources - intents, local content, assets. The test case covers related PRs test examples in order to avoid regression.
Maybe we can have unit test only checking if the callback of the requestThumbnailAtTimes is called successfully?

Test case:
app.js

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;
}

The sample video should be put under Resources of the app folder and in the Downloads folder of the device.
Video: http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4

@build
Copy link
Contributor

build commented Feb 12, 2018

Messages
📖

👍 Hey!, You deleted more code than you added. That's awesome!

📖

💾 Here's the generated SDK zipfile.

Generated by 🚫 dangerJS

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS

@build build added the android label Feb 14, 2018
Copy link
Contributor

@ssjsamir ssjsamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FR Passed: Was able to get a thumbnail for remote content.

Test steps:

  • Used the generated SDK above to build the PR
  • Copied the code from the test case above in to the a Titanium project
  • Replaced the link in the test case as it was dead; replaced with http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4
  • Ran the program
  • Clicked remote content
  • was able to select a thumbnail using the scroll bar
  • Was able to verify thumbnails on other options as well (Local content, gallery and camera)

Test Environment
APPC Studio: 5.0.0.201711280737
APPC CLI: 7.0.1
Device: Nexus 6p (8.1.0)
Operating System Name: Mac OS High Sierra
Operating System Version: 10.13
Node.js Version: 8.9.1

@ssjsamir ssjsamir merged commit 6ce615d into tidev:master Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants