Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23686] Windows: Implement CameraOptionsType.whichCamera

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-08-03T08:22:58.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsWindows
Labelsn/a
ReporterGary Mathews
AssigneeGary Mathews
Created2016-07-26T18:09:35.000+0000
Updated2016-08-29T13:13:45.000+0000

Description

Currently, it is not possible to specify which camera (front or rear) to use. Use DeviceInformation::FindAllAsync(DeviceClass::VideoCapture) to find the Id of the specified camera and set the VideoDeviceId of MediaCaptureInitializationSettings *Test Case* Setting whichCamera: Titanium.Media.CAMERA_FRONT should show front camera preview.
var win = Ti.UI.createWindow({ backgroundColor: 'green', layout: 'vertical' }),
    openButton = Ti.UI.createButton({ title: 'OPEN CAMERA', backgroundColor: 'blue' }),
    imageView = Ti.UI.createImageView({ width: Ti.UI.FILL, height: '70%' });

var overlay = Ti.UI.createView({
    layout: 'vertical',
    height: '20%', width: Ti.UI.FILL,
    bottom: 0
}),
takeButton = Ti.UI.createButton({ title: 'TAKE A PHOTO', backgroundColor: 'red' }),
hideButton = Ti.UI.createButton({ title: 'HIDE PREVIEW', backgroundColor: 'red' });

takeButton.addEventListener('click', function () {
    Ti.Media.takePicture();
});
hideButton.addEventListener('click', function () {
    Ti.Media.hideCamera();
});
overlay.add(takeButton);
overlay.add(hideButton);

openButton.addEventListener('click', function () {
    Ti.Media.showCamera({
        whichCamera: Titanium.Media.CAMERA_FRONT, // Titanium.Media.CAMERA_REAR
        mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
        overlay: overlay,
        success: function (e) {
            Ti.API.info('showCamera() success');
            imageView.image = e.media;
        },
        error: function (e) {
            alert('showCamera() error: ' + JSON.stringify(e));
        }
    });
});

win.add(openButton);
win.add(imageView);
win.open();

Comments

  1. Gary Mathews 2016-08-02

    master: https://github.com/appcelerator/titanium_mobile_windows/pull/797
  2. Ewan Harris 2016-08-29

    Verified using: Windows 10 Pro Appc core: 6.0.0-31 Appc NPM: 4.2.8-5 Ti SDK: 6.0.0.v20160829005859 Lumia 520 8.1 Lumia 930 10.0 Using the example code above the camera preview can be set to either the front or back, setting an invalid option or no option will set it to the default for the device Closing ticket

JSON Source