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

fix(ios): fix orientation of the thumbnail image created from a video #13859

Merged
merged 1 commit into from Jun 20, 2023

Conversation

alexlarocca
Copy link
Sponsor Contributor

This will fix the orientation of the thumbnail

GitHub discussions: https://github.com/tidev/titanium-sdk/discussions/[ID]

Provide a clear PR title prefixed with [ID]

Optional Description:

This will fix the orientation of the thumbnail
@m1ga m1ga changed the title Fix orientation of the thumbnail image created from a video fix(ios): fix orientation of the thumbnail image created from a video Jun 19, 2023
@alexlarocca
Copy link
Sponsor Contributor Author

alexlarocca commented Jun 19, 2023

Code for testing. To reproduce the issue, take a video with the phone upside down.

var win = Ti.UI.createWindow({backgroundColor: 'white'});

var selectButton = Ti.UI.createButton({title: 'Select Video', top: 50});
win.add(selectButton);

selectButton.addEventListener('click', function() {
	imageView.image = null;
	Ti.Media.requestPhotoGalleryPermissions(function (e) {
		if (e.success) {
			Ti.Media.openPhotoGallery({
				mediaTypes: [Ti.Media.MEDIA_TYPE_VIDEO], 
				success: onSelectVideo
			});
		}
	});
});

var coverFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'cover.jpg');
var videoFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'video.mov');

function onSelectVideo(e) {
	videoFile.write(e.media); 		

	var displayCaps = Ti.Platform.displayCaps;

	var videoPlayer = Ti.Media.createVideoPlayer({
		mediaControlStyle: Ti.Media.VIDEO_CONTROL_NONE,
		width: displayCaps.platformWidth, height: displayCaps.platformHeight, 
		autoplay: false,
		url: videoFile.nativePath,
	});
	
	videoPlayer.requestThumbnailImagesAtTimes([0], Ti.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME, function(e) {
		coverFile.write(e.image); 		
		videoPlayer.stop();
		videoPlayer.release();
		videoPlayer = null;
		imageView.image = coverFile.nativePath;
	});
}

var imageView = Ti.UI.createImageView({
    width: 300, height: 300,
	scalingMode: Ti.Media.IMAGE_SCALING_ASPECT_FIT,
})
win.add(imageView);

win.open();

@hansemannn
Copy link
Collaborator

Thank you Alex, the changes look and work good!

@hansemannn hansemannn merged commit 70e0393 into tidev:master Jun 20, 2023
@alexlarocca alexlarocca deleted the patch-1 branch June 22, 2023 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants