Created
April 16, 2015 08:19
-
-
Save rajubd49/88274de194ac807bccbb to your computer and use it in GitHub Desktop.
Camera Switching and camera support checking - Appcelerator Titanium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Titanium.UI.setBackgroundColor('#000'); | |
var win1 = Titanium.UI.createWindow({ | |
title:'Tab 1', | |
backgroundColor:'#fff' | |
}); | |
var aButton = Ti.UI.createButton({ | |
title : 'Camera', | |
height : 50, | |
width : 100, | |
top : 50, | |
left : 50 | |
}); | |
aButton.addEventListener('click', function() { | |
if (Ti.Media.isCameraSupported) { //Ti.Media.isCameraSupported is used to check if the Camera is available and then you can use built in facility for switching between cameras. | |
Titanium.Media.showCamera({ | |
success : function(event) { | |
// called when media returned from the camera | |
Ti.API.debug('Our type was: ' + event.mediaType); | |
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { | |
var imageView = Ti.UI.createImageView({ | |
width : win.width, | |
height : win.height, | |
image : event.media | |
}); | |
win.add(imageView); | |
} else { | |
alert("got the wrong type back =" + event.mediaType); | |
} | |
}, | |
cancel : function() { | |
// called when user cancels taking a picture | |
}, | |
error : function(error) { | |
// called when there's an 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(); | |
}, | |
saveToPhotoGallery : true, | |
allowEditing : true, | |
mediaTypes : [Ti.Media.MEDIA_TYPE_VIDEO, Ti.Media.MEDIA_TYPE_PHOTO], | |
showControls : true // always use to get the basic facility about camera. | |
//overlay:overlayview // do not use overlay to when you want to use the switching facility | |
}); | |
} | |
}); | |
win1.add(aButton); | |
win1.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment