here's a simple example for you.
it shows 2 different ways to control some element on a webview.
the example loads a simple webview from dirassets.
there is a sleep command for 10 seconds so you can settle down and look at the webview (i don't want you to miss the show

.)
the first example executes a javascript command to change the text color of an element directly. comment that one and uncomment the second one.
the second example executes a javascript function which does the same thing.
i believe either case could work for you.
if you leave both uncommented, you will only see the result of the second example.
note: there is a button on the webview. if you tap it, the color changes. understand that the webviewextras executejavascript command that runs a function (the second example) is clicking the button programatically, as if you had tapped the button.
Sorry for my late response, i was trying to do everything by twisting your code to solve problem at hand. Thank you for that your code; it was so simple and better than the one i was using to achieve the same result discussed in previous posts. Even the dullest can understand your own, i have learnt from your own. In this your code, html is still being loaded into webrtc webview like i pointed out before. In my own case, the html is already loaded from
https://appr.tc/r/009 via WebView1.LoadUrl("
https://appr.tc/r/009") and not stored in dirasset through code below.
F
ull source code is here posted by Erel
[CODE lang="b4x" title="Webrtc Html that shows on B4A webview"]#Region Project Attributes
#ApplicationLabel: B4A Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private rp As RuntimePermissions
End Sub
Sub Globals
Private WebView1 As WebView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
If Result Then
Dim client As JavaObject
client.InitializeNewInstance(Application.PackageName & ".main$MyChromeClient", Null)
Dim jo As JavaObject = WebView1
jo.RunMethod("setWebChromeClient", Array(client))
WebView1.LoadUrl("https://appr.tc/r/009")
End If
End If
End Sub
#if Java
import android.webkit.*;
public static class MyChromeClient extends WebChromeClient {
@override
public void onPermissionRequest(PermissionRequest request) {
request.grant(request.getResources());
}
}
#End If
[/CODE]
When the code above is run on phone, it displays a streaming session using default front camera, but i have read online and based on what Erel said that javascript function can be used to change the camera from front to back camera. . Now, i have been able to search for javascript like this below that i assumed can change the camera to back camera:
[CODE lang="b4x" title="Unverified Javascript functions for changing front to back camera in webrtc webview"]// camera stream video element
let videoElm = document.querySelector('#camera-stream');
// flip button element
let flipBtn = document.querySelector('#flip-btn');
// default user media options
let defaultsOpts = { audio: false, video: true }
let shouldFaceUser = true;
// check whether we can use facingMode
let supports = navigator.mediaDevices.getSupportedConstraints();
if( supports['facingMode'] === true ) {
flipBtn.disabled = false;
}
let stream = null;
function capture() {
defaultsOpts.video = { facingMode: shouldFaceUser ? 'user' : 'environment' }
navigator.mediaDevices.getUserMedia(defaultsOpts)
.then(function(_stream) {
stream = _stream;
videoElm.srcObject = stream;
videoElm.play();
})
.catch(function(err) {
console.log(err)
});
}
flipBtn.addEventListener('click', function(){
if( stream == null ) return
// we need to flip, stop everything
stream.getTracks().forEach(t => {
t.stop();
});
// toggle / flip
shouldFaceUser = !shouldFaceUser;
capture();
})
capture();[/CODE]
Now, my question is this, how can i pass this javascript function to already displaying webrtc webview (not the one i will load from dirasset) to cause my phone to change its camera to back camera from B4A?
Note: I am open to any other solution like java or otherwise that can solve problem at hand. Hope is clearer now? Thank you for your time,
Regards