[TIMOB-24105] iOS: Support using volume buttons with custom camera controls.
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | n/a |
Reporter | Motiur Rahman |
Assignee | Unknown |
Created | 2016-11-04T18:07:04.000+0000 |
Updated | 2019-03-10T21:30:12.000+0000 |
Description
Currently, if we set *showControls : false* for using camera overlay then volume event is not fired.
- http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Media-event-volume
We came to know that this is not natively possible without using private api's that will lead to rejected apps.
- http://stackoverflow.com/a/8284443/5537752
- http://stackoverflow.com/questions/7839914/initiate-image-capture-using-volume-button-avcapturesession
But we see WhatsApp and Snapchat allow it.
So you can check this library which claims to do it
- https://github.com/jpsim/JPSVolumeButtonHandler
Test code
var win = Ti.UI.createWindow({
layout : "vertical"
});
win.open();
var value = 0;
var button = Ti.UI.createButton({
title : "Camera",
top : 20,
width : 200,
height : 200
});
button.addEventListener("click", takePics);
win.add(button);
var value = 0;
var view = Ti.UI.createView();
var overlay = Ti.UI.createView({
bottom : 20,
backgroundColor : "white",
width : 70,
height : 70,
borderRadius : 35
});
var done = Ti.UI.createButton({
bottom : 20,
title : "Done",
right : 20,
backgroundColor : "red",
width : 50,
height : 50,
borderRadius : 25
});
// Create a Label.
var number = Ti.UI.createButton({
color : '#000',
font : {
fontSize : 10
},
});
done.addEventListener('click', function() {
number.setTitle("");
value = 0;
Ti.Media.hideCamera();
});
// Add to the parent view.
view.add(overlay);
view.add(done);
overlay.add(number);
function takePics() {
//alert('You were granted permission.');
Ti.Media.showCamera({
success : function(e) {
Ti.API.info(e.media);
value++;
number.setTitle(value);
},
error : function(e) {
alert(e);
},
autohide : false,
overlay : view,
saveToPhotoGallery : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
showControls : false
});
}
number.addEventListener('click', function(e) {
Ti.Media.takePicture();
});
var currentVolume = Ti.Media.getVolume();
Ti.Media.addEventListener('volume', function(e) {
alert('click on voluum up button');
// Compare with old value to check the volume up, take picture afterwards
if (e.volume > currentVolume) {
Ti.Media.takePicture();
}
currentVolume = volume;
});
Thanks.
No comments