Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15976] iOS: Turning the camera around using Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT) causing camera to get stuck and refuse to snap a picture

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2016-08-11T20:02:03.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsiOS
LabelsTi.Media.switchCamera, camera, ios, picture, qe-6.0.0
ReporterStevo Perisic
AssigneeAngel Petkov
Created2013-11-07T14:35:06.000+0000
Updated2016-09-22T18:49:42.000+0000

Description

Turning the camera around using Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT) and subsequently trying to snap a picture using Ti.Media.takePicture(); causes the camera to freeze/get stuck and this error is shown in the iPad console: UIImagePickerController: ignoring request to take picture; camera is changing modes.

Comments

  1. Mauro Parra-Miranda 2013-11-21

    Hello Stevo, can you please provide a testcase and a log? TIA! Best, Mauro
  2. Mostafizur Rahman 2013-12-04

    The issue is not reproducible with the sample code posted below. When I switch views and press the "Take Picture" button, I get the expected output and do not see any errors or freezing. Can you please try this sample to see if you get the error on your device? Please keep us posted with an update.

    Test Device:

    iPad with 7.0.4.

    Sample Code

       container = {};
       container.win = Titanium.UI.createWindow();
       
       container.button = Titanium.UI.createButton({
       	color : '#fff',
       	backgroundImage : '/images/BUTT_grn_on.png',
       	backgroundSelectedImage : '/images/BUTT_grn_off.png',
       	backgroundDisabledImage : '/images/BUTT_gry_on.png',
       	bottom : 10,
       	width : 301,
       	height : 57,
       	font : {
       		fontSize : 20,
       		fontWeight : 'bold',
       		fontFamily : 'Helvetica Neue'
       	},
       	title : 'Take Picture'
       });
       
       container.overlay = Titanium.UI.createView();
       container.overlay.add(container.button);
       
       container.button.addEventListener('click', function() {
       
       	Ti.Media.takePicture();
       
       });
       
       container.switchCamera = Titanium.UI.createButton({
       	color : '#fff',
       	backgroundImage : '/images/BUTT_grn_on.png',
       	backgroundSelectedImage : '/images/BUTT_grn_off.png',
       	backgroundDisabledImage : '/images/BUTT_gry_on.png',
       	top : 10,
       	width : 301,
       	height : 57,
       	font : {
       		fontSize : 20,
       		fontWeight : 'bold',
       		fontFamily : 'Helvetica Neue'
       	},
       	title : 'switch Camera'
       });
       container.overlay.add(container.switchCamera);
       container.switchCamera.addEventListener('click', function() {
       
       	Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT);
       
       });
       
       Titanium.Media.showCamera({
       
       	success : function(event) {
       		Ti.API.debug("picture was taken");
       
       		// place our picture into our window
       		var imageView = Ti.UI.createImageView({
       			image : event.media,
       			width : container.win.width,
       			height : container.win.height
       		});
       		container.win.add(imageView);
       
       		// programatically hide the camera
       		//Ti.Media.hideCamera();
       	},
       	cancel : function() {
       	},
       	error : function(error) {
       		var a = Titanium.UI.createAlertDialog({
       			title : 'Camera'
       		});
       		if (error.code == Titanium.Media.NO_CAMERA) {
       			a.setMessage('Please run this test on device');
       		} else {
       			a.setMessage('Unexpected error: ' + error.code);
       		}
       		a.show();
       	},
       	overlay : container.overlay,
       	showControls : false, // don't show system controls
       	mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO,
       	autohide : false // tell the system not to auto-hide and we'll do it ourself
       });
       container.win.open();
       
       
  3. Stevo Perisic 2013-12-07

    Here is the code I used and you can reproduce every time, the user clicks the take photo button fast, Titanium 3.1.3.GA, iPad 7.0.2:
       var overlay = Ti.UI.createView({
       	width: Ti.UI.FILL,
       	height: Ti.UI.FILL,
       	backgroundColor: 'transparent'
       });
       
       var takePhotoBtn = Ti.UI.createButton({
       	width: '200dp',
       	height: '60dp',
       	bottom: '100dp',
       	backgroundColor: '#FFF'
       });
       
       var btnLbl = Ti.UI.createLabel({
       	text: 'Take Photo'
       });
       
       takePhotoBtn.addEventListener('click', function(e){
       	Ti.Media.takePicture()
       });
       
       takePhotoBtn.add(btnLbl);
       overlay.add(takePhotoBtn);
       
       $.back.addEventListener('click', showCamera);
       
       $.index.open();
       
       function showCamera(){
       	Ti.Media.showCamera({
       		success: function(event){
       			var imageData = event.media;
       			$.resultImg.setImage(imageData);
       			Ti.Media.hideCamera();
       		},
       		error: function(error){
       			Ti.API.info('Error: ' + JSON.stringify(error));
       		},
       		overlay : overlay,
       		saveToPhotoGallery: false,
       		allowEditing: false,
       		mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
       		showControls : false,
       		autohide : false,
       		//make the picture inside the camera smaller so that we 
       		//can than place an overlay around it
       		transform: Ti.UI.create2DMatrix({
       			scale : 0.5
       		})
       	});
       
       	Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT);	
       }
       
       
       <Alloy>
       	<Window class="container">
       		<Button id="back" title="Start camera"/>
       		<ImageView id="resultImg"/>
       	</Window>
       </Alloy>
       
       ".container": {
       	backgroundColor:"white",
       	layout: 'vertical'
       },
       "#back":{
       	top: '60dp'
       },
       "#resultImg":{
       	width: '500dp',
       	height: '500dp',
       	top: '20dp'
       }
       
  4. Eric Wieber 2013-12-13

    When testing the above code on an iPad (7.0.4), I was able to reproduce the issue. If I immediately tap the "Take Photo" button after tapping the "Start Camera" button then the app will take a picture, but the next time I try to start the camera and take a picture, I am unable to tab the "Take Photo" button. I was also able to reproduce this on an iPhone 5 running 7.0.3. Escalating this ticket to bugs.
  5. Harry Bryant 2016-09-22

    Verified as fixed, using the provided test code, I not able to reproduce the error. Tested On: iPhone 6 Plus 10.0.1 Device iPhone 5S 9.3.5 Device Mac OSX El Capitan 10.11.6 Ti SDK: 6.0.0.v20160921191053 Appc Studio: 4.8.0.201609101003 Appc NPM: 4.2.8-6 App CLI: 6.0.0-45 Xcode 8.0 Node v4.4.7 *Closing ticket.*

JSON Source