falex
November 29, 2019, 5:33am
1
Hi All ,
I am working with AR sample using ObjectTrackerCamera class , but i changed the method to get the enviroment cam. The code working ok on my desktop when use CreateFromWebCamAsync , but on the mobile not working and just show black screen.
I replace the method using CreateFromStreamAsync to support stream directly using this constraint
{ audio: false, video: {facingMode: “environment” } }
if (navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia) {
this._stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: {facingMode: "environment" } });
}
the behaviour was just a black screen from mobile.
Any advice is welcome.
This is my first week using Babylon :-).
Regards,
Falex
sebavan
November 29, 2019, 12:03pm
2
Welcome to the forum @falex !!!
Adding @syntheticmagus for the AR part.
Could you try to reproduce your issue in the playground ? It might help all of us figuring out the issue.
I hope that this exemple can help u :
AR exemple : https://www.babylonjs-playground.com/#BCU1XR#802
falex
November 29, 2019, 2:33pm
5
sebavan:
playground
Thanks for reply , let me check, because include this code in vue typescript project. I think will be simple to use github page for me.
Regards,
Falex
falex
November 29, 2019, 2:34pm
6
thanks issam_abdelhedi , let me review the complete code.
Regards,
Falex
falex
November 29, 2019, 3:01pm
7
issam_abdelhedi ,
I am using this code to create videoTexture and using Layer to create backgroundLayer, but about your code i not clear how to include this object.
the code
import { Camera, Layer, Observer, Scene, Texture, Tools, Vector3, VideoTexture } from "babylonjs"
export class ObjectTrackerCamera extends Camera {
public videoTexture: VideoTexture;
private _layer: Layer;
private _beforeRenderObserver: Observer<Layer>;
private constructor(name: string, scene: Scene) {
super(name, Vector3.Zero(), scene);
this._layer = new Layer(name + "_backgroundLayer", null, scene);
}
public static async CreateAsync(name: string, scene: Scene): Promise<ObjectTrackerCamera> {
scene.clearColor.set(0, 0, 0, 1);
const camera = new ObjectTrackerCamera(name, scene);
camera.fovMode = Camera.FOVMODE_VERTICAL_FIXED;
camera.fov = Tools.ToRadians(40); // TODO: Magic number
This file has been truncated. show original
In line 36 using this api
camera.videoTexture = await BABYLON.VideoTexture.CreateFromStreamAsync(scene,stream);
I am using this code to get MediaStream :
private async startDevice () {
try {
if (navigator.mediaDevices &&
navigator.mediaDevices.getUserMedia) {
this._stream = await navigator.mediaDevices.getUserMedia({ audio: false, video: {facingMode: "environment" } });
}
} catch (e) {
this.handleError(e)
} // end try
}
Any advice is welcome.
Falex
sebavan
November 29, 2019, 3:17pm
8
So definitely a mission for @syntheticmagus who is currently enjoying thanksgiving but no worries He ll be back on Monday.
(Thanks for pinging me on this, Seb!)
Hi falex,
Does your browser’s console log show any errors? There are some nuances to creating video textures sometimes, and it’s very possible that there are issues (syntax support, etc.) where we simply haven’t handled the appropriate special cases yet. Specifically, in one of my browsers (the new Edge beta) I’m seeing an error message I haven’t seen before or tracked down yet.
I’ll take a look at that later to see if I can track down where that’s coming from. In the meantime, though, can you check and see if you’re getting a similar error message in the circumstance that’s not working? Thanks!
falex
December 4, 2019, 6:07pm
11
Thanks for your reply @syntheticmagus , let me re-test again, I used code from Texture.js and handler video and strem in my code.
camera.videoTexture = await new Promise<BABYLON.VideoTexture>((resolve) => {
let onPlaying = () => {
resolve(new BABYLON.VideoTexture("video", video, scene, true, true));
video.removeEventListener("playing", onPlaying);
};
//video.addEventListener("playing", onPlaying);
//video.play();
});
Thanks for your reply
Falex