Skip to content

impr: implement promise support to platform specific APIs#13018

Open
garymathews wants to merge 19 commits into
tidev:mainfrom
garymathews:TIMOB-28279
Open

impr: implement promise support to platform specific APIs#13018
garymathews wants to merge 19 commits into
tidev:mainfrom
garymathews:TIMOB-28279

Conversation

@garymathews

@garymathews garymathews commented Aug 11, 2021

Copy link
Copy Markdown
Contributor
  • Implement promise support to
    • Titanium.Geolocation.requestTemporaryFullAccuracyAuthorization()
    • Titanium.Media.Android.scanMediaFiles()
    • Titanium.Media.requestMusicLibraryPermissions()
    • Titanium.Media.takeScreenshot()
    • Titanium.Media.VideoPlayer.requestThumbnailImagesAtTimes()
TEST CASES
requestTemporaryFullAccuracyAuthorization (iOS)
const win = Ti.UI.createWindow();
const btn = Ti.UI.createButton({ title: 'requestTemporaryFullAccuracyAuthorization' });

btn.addEventListener('click', async _ => {
	const e = await Ti.Geolocation.requestTemporaryFullAccuracyAuthorization();
	alert(JSON.stringify(e, null, 1));
});

win.add(btn);
win.open();
requestMusicLibraryPermissions (iOS)
const win = Ti.UI.createWindow();
const btn = Ti.UI.createButton({ title: 'requestMusicLibraryPermissions' });

btn.addEventListener('click', async _ => {
	const e = await Ti.Media.requestMusicLibraryPermissions();
	alert(JSON.stringify(e, null, 1));
});

win.add(btn);
win.open();
scanMediaFiles (Android)
const win = Ti.UI.createWindow();
const btn = Ti.UI.createButton({ title: 'Scan' });

btn.addEventListener('click', async _ => {
	let file = Ti.Filesystem.getFile('image.jpg'); // Use any jpg as `image.jpg`
	file.copy(Ti.Filesystem.applicationDataDirectory + '/temp.jpg');
	file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + '/temp.jpg');

	const scanned = await Ti.Media.Android.scanMediaFiles([ file.nativePath ], null);

	alert(`Scanned: ${scanned.length} file.\n\n${scanned[0].path}`);
});

win.add(btn);
win.open();
takeScreenshot (iOS, Android)
const win = Ti.UI.createWindow({ layout: 'vertical' });
const frame = Ti.UI.createImageView({
	width: '67%',
	height: '80%',
	backgroundColor: 'red'
});
const btn = Ti.UI.createButton({ title: 'Screenshot' });

btn.addEventListener('click', async _ => {
	const screenshot = await Ti.Media.takeScreenshot();

	frame.image = screenshot.media;
});

win.add([ frame, btn ]);
win.open();
requestThumbnailImagesAtTimes (iOS, Android 6.0+)
const win = Ti.UI.createWindow({ layout: 'vertical' });
const frame = Ti.UI.createImageView({
	width: 320,
	height: 176,
	backgroundColor: 'red'
});
const btn = Ti.UI.createButton({ title: 'Frame' });
const slider = Ti.UI.createSlider();
const player = Ti.Media.createVideoPlayer({
	url: 'mov_bbb.mp4',
	autoplay: false,
	height: 320,
	width: 176
});

player.addEventListener('durationavailable', e => {
	player.visible = false;
	slider.max = e.duration;
});

btn.addEventListener('click', async _ => {
	const frames = await player.requestThumbnailImagesAtTimes(
		[ slider.value/1000 ],
		Ti.Media.VIDEO_TIME_OPTION_NEAREST_KEYFRAME
	);

	for (const f of frames ) {
		if (f.success) {
			frame.image = f.image;
			break;
		}
	}
});

win.add([ frame, btn, slider, player ]);
win.open();

JIRA Ticket

@build

build commented Aug 11, 2021

Copy link
Copy Markdown
Contributor
Fails
🚫 Test reports missing for Android Main. This indicates that a build failed or the test app crashed
Warnings
⚠️ Tests have failed, see below for more information.
⚠️ This PR has milestone set to 10.2.0, but the version defined in package.json is 10.1.0 Please either: - Update the milestone on the PR - Update the version in package.json - Hold the PR to be merged later after a release and version bump on this branch
Messages
📖 ❌ 2 tests have failed There are 2 tests failing and 940 skipped out of 15563 total tests.
📖 ✊ The commits in this PR match our conventions! Feel free to Rebase and Merge this PR when ready.

Tests:

ClassnameNameTimeError
android.emulator.5.0.Titanium.Media.Android.methods#scanMediaFiles promise (5.0.2)0.207
Error: expected '/data/data/com.appcelerator.testApp.testing/app_appdata/temp.jpg' to equal 'file://file:///data/data/com.appcelerator.testApp.testing/app_appdata/temp.jpg'
at Assertion.fail (/node_modules/should/cjs/should.js:275:13)
      at Assertion.value (/node_modules/should/cjs/should.js:356:9)
      at Context.<anonymous> (/ti.media.android.test.js:60:25)
android.emulator.5.0.Titanium.Media.Android.methods#scanMediaFiles callback (5.0.2)0.153
Error: Uncaught Uncaught AssertionError

Generated by 🚫 dangerJS against 89ed3dc

@garymathews garymathews force-pushed the TIMOB-28279 branch 5 times, most recently from 9e9db75 to 04ca525 Compare September 13, 2021 23:50
mTiThumbnailRetriever.getBitmap(TiConvert.toIntArray(times), TiConvert.toInt(option),
createThumbnailResponseHandler(callback));
}
promise.resolve(new KrollDict[0]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we call reject() instead since the required URL property was not provided?

@hansemannn hansemannn modified the milestones: 11.0.0, 11.1.0 May 27, 2022
@hansemannn hansemannn modified the milestones: 11.1.0, 12.0.0 Oct 7, 2022
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.

4 participants