Created
May 12, 2016 05:08
-
-
Save rakhimoni/0e7655b707da5d26b53d384ef8545a92 to your computer and use it in GitHub Desktop.
This example is only able to capture video on the iOS platform.
This file contains hidden or 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 win = Titanium.UI.createWindow({ | |
| title : 'Tab 1', | |
| backgroundColor : '#fff' | |
| }); | |
| var camera = Ti.UI.createButton({ | |
| title : 'Camera', | |
| height : 50, | |
| width : 100, | |
| top : 50, | |
| left : 50 | |
| }); | |
| camera.addEventListener('click', function() { | |
| if (Ti.Media.isCameraSupported) { | |
| //Ti.Media.setCameraFlashMode(Ti.Media.CAMERA_FLASH_ON); | |
| //Ti.Media.setCameraFlashMode(1); | |
| //alert(Ti.Media.getCameraFlashMode()); | |
| //check if this return 0 always | |
| Titanium.Media.showCamera({ | |
| success : function(event) { | |
| Ti.API.debug('Our type was: ' + event.mediaType); | |
| if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) { | |
| var imageView = Ti.UI.createImageView({ | |
| width : "300", | |
| height : "200", | |
| 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 | |
| }); | |
| } | |
| }); | |
| win.add(camera); | |
| win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment