Comments (14)
Hi everyone, I have been working on the chance to switch between front and back camera on the fly during an AR session.
Here's the repo: https://github.com/fcor/arjs-switch-cam
And here's the live version: https://fcor.github.io/arjs-switch-cam/
It would be great if you can give it a try and let me know how does it work and any comment/suggestion you may have
It's widely tested on Android and seems to be fine on Chrome, Firefox (could be slower sometimes), and Edge. On iPhone it has been tested on some devices but seems that it's not 100% perfect.
from ar.js.
Hi, is there any updates here?
For newer phones with multiple back cameras, AR.js would choose the default one, which in some phones it might be a zoomed camera, is there a way to detect the default zoom scale camera or ask user to choose the camera they want to display ?
Thanks in advance.
Update:
I managed to create the camera-selection feature by refering to this github and this article.
Basically, adding an extra file, the app.js from the github link and link it in your html file, and change the
const video = document.getElementById('video');
to
const video = document.getElementById('arjs-video');
Add the following code in html file:
<div class="controls">
<button id="button">Get camera</button>
<select id="select">
<option></option>
</select>
The rest should be working fine. However, in my case, i need to change:
navigator.mediaDevices
.getUserMedia(constraints)
.then(stream =>{
currentStream = stream;
video.srcObject = stream;
return navigator.mediaDevices.enumerateDevices();
})
.then(gotDevices)
.catch(error => {
console.error(error);
});
});
to
navigator.mediaDevices
.getUserMedia(constraints)
.then((stream) => {
currentStream = stream;
document.getElementById('arjs-video').srcObject = stream;
var event = new CustomEvent("camera-init", { stream: stream });
window.dispatchEvent(event);
document.body.addEventListener("click", function () {
document.getElementById('arjs-video').play();
});
return navigator.mediaDevices.enumerateDevices();
})
.then(gotDevices)
.catch((error) => {
console.error(error);
});
Hope this help those people who are looking for changing back cameras in mobile phones.
from ar.js.
What is the situation here? (beside closed)
Is there a branch to test, which allows to select a different camera? (with three.js)
from ar.js.
any news? i would like to test
from ar.js.
Here is someting I find. maybe will help it's a Html5 select camera demo
from ar.js.
Hi Everyone,
Just checking to see what the best solution is to select a different camera on Android mobile devices? This is a program breaking bug and I cannot find a solution to this. The default camera chrome devices chooses is a telephoto lens that is very "zoomed in" and shaky. I also do not have the option of using a firefox browser, as the new Huawei's coming out currently do not support firefox browser?Please can someone point me to a possible solution? The HTML5 select camera demo is a bit complicated to incorporate due to my coding skills?
from ar.js.
Hi, also chiming in to relight this issue. I'm googling and fiddling since hours, but didn't succeed to have it fixed. Is there still any workaround available on v3.3.1?
Thanks,
eC
from ar.js.
Nope, but @fcor is working on this. Hopefully we are progressing on this
from ar.js.
Hi everyone, I have been working on the chance to switch between front and back camera on the fly during an AR session.
Here's the repo: https://github.com/fcor/arjs-switch-cam
And here's the live version: https://fcor.github.io/arjs-switch-cam/
It would be great if you can give it a try and let me know how does it work and any comment/suggestion you may have
😃 It's widely tested on Android and seems to be fine on Chrome, Firefox (could be slower sometimes), and Edge. On iPhone it has been tested on some devices but seems that it's not 100% perfect.
It does not work anymore on Android Chrome v 86.0.4240 and iOS Chrome v 86.0.4240
Edge 45.09.4, tried it on my Samsung S10 device.
from ar.js.
Although live version by @fcor didn't work for me for some reason - after I've copied his code into my app it worked without any problems!
Upvoting this feature - it is quite convenient in complex cases.
from ar.js.
Hello everyone,
We've been facing with this issue for the last couple of weeks. Today we will test @fcor solution and see if this works.
Acording to other solutions using deviceId instead of facingMode
from ar.js.
Hi, is there any updates here?
For newer phones with multiple back cameras, AR.js would choose the default one, which in some phones it might be a zoomed camera, is there a way to detect the default zoom scale camera or ask user to choose the camera they want to display ?
Thanks in advance.
Update: I managed to create the camera-selection feature by refering to this github and this article.
Basically, adding an extra file, the app.js from the github link and link it in your html file, and change the
const video = document.getElementById('video');
toconst video = document.getElementById('arjs-video');
Add the following code in html file:
<div class="controls"> <button id="button">Get camera</button> <select id="select"> <option></option> </select>
The rest should be working fine. However, in my case, i need to change:
navigator.mediaDevices .getUserMedia(constraints) .then(stream =>{ currentStream = stream; video.srcObject = stream; return navigator.mediaDevices.enumerateDevices(); }) .then(gotDevices) .catch(error => { console.error(error); }); });
to
navigator.mediaDevices .getUserMedia(constraints) .then((stream) => { currentStream = stream; document.getElementById('arjs-video').srcObject = stream; var event = new CustomEvent("camera-init", { stream: stream }); window.dispatchEvent(event); document.body.addEventListener("click", function () { document.getElementById('arjs-video').play(); }); return navigator.mediaDevices.enumerateDevices(); }) .then(gotDevices) .catch((error) => { console.error(error); });
Hope this help those people who are looking for changing back cameras in mobile phones.
This solves my problem, Thanks!
from ar.js.
Hi follow all your steps but can't gei cameras lis
t
from ar.js.
Hi,
The reason it is not showing could be because :
- only one camera is working right now (the default one), which is the one has been selected.
- Something is wrong with your code.
I suggest you to try out the code in this article to see if your other cameras are working fine.
from ar.js.
Related Issues (20)
- gps-new-camera iOS Errors HOT 2
- Which is the Three.js version? HOT 2
- Draw on webcam canvas prior to AR.js processing it
- 404 on https://raw.githack.com/AR-js-org/AR.js/master/three.js/build/ar-nft.js HOT 2
- Error when loading AR.js three.js location only build HOT 5
- android WebRTC Issue - Navigator.MediaDevice is not presented in your device HOT 2
- Modal is not rotating on mobile movement
- AFrame-ar who to get canvas?
- location based ar drift issue HOT 21
- Does it even work? HOT 14
- Wrong position click on model AR.js HOT 16
- Could not show Video in Wechat HOT 1
- [bug report] Stretched camera feed HOT 16
- [feature request] Implement floating origin on geolocation ar HOT 10
- [feature request] SimulateLatitude, SimulateLongitude work even if gps is turned on HOT 11
- [bug report] gps permission is asked twice on chrome for windows HOT 1
- [bug report] gps-new-entity-place distance property unavailable HOT 9
- "Multiple instances of Three.js being imported." warning, when working with npm packages of three.js and AR.js in one project HOT 17
- TypeScript version of the library and modularity HOT 6
- The demo link is not loading
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ar.js.