B4J Question [ Webview ] have a way to enable micrpohone and webcam ?

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
hello everyone !
i am trying to list microphone and webcam using webview ( html and js ), but dont works ... have a way to do it ?


i am loading this page with webview to test : https://mictests.com

1633830195726.png
 

drgottjr

Expert
Licensed User
Longtime User
so, the thread says "enable" microphone and webcam. the post says "list" microphone and webcam. obviously a big difference.
assuming you merely want to list the devices (which i don't actually believe is the case), here is what you do:

add a webview to your project
add webviewextras to the project
add chromeclient in webviewextras
in the attachment below there are 2 files:
1) devices.html (for listing the devices)
2) devices.png (an example of what i see when i run the script on one of my devices)
add devices.html to your project (dir.assets)
when you build and run the app, after you have added a webview and chromeclient, you read in devices.html
load the webview. it will show an alert similar to what you see in devices.png. in fact you see only data which
are available to you. there is no guarantee what is available. don't ask why you cannot see more. you see only
the data that's available. period.
note: i loaded the webview as follows
B4X:
webview.loadhtml( file.readstring( file.dirassets, "devices.html"))
you are, of course, free to use whatever method you wish.
 

Attachments

  • devices.zip
    34.4 KB · Views: 186
Upvote 0

Waldemar Lima

Well-Known Member
Licensed User
Longtime User
so, the thread says "enable" microphone and webcam. the post says "list" microphone and webcam. obviously a big difference.
assuming you merely want to list the devices (which i don't actually believe is the case), here is what you do:

add a webview to your project
add webviewextras to the project
add chromeclient in webviewextras
in the attachment below there are 2 files:
1) devices.html (for listing the devices)
2) devices.png (an example of what i see when i run the script on one of my devices)
add devices.html to your project (dir.assets)
when you build and run the app, after you have added a webview and chromeclient, you read in devices.html
load the webview. it will show an alert similar to what you see in devices.png. in fact you see only data which
are available to you. there is no guarantee what is available. don't ask why you cannot see more. you see only
the data that's available. period.
note: i loaded the webview as follows
B4X:
webview.loadhtml( file.readstring( file.dirassets, "devices.html"))
you are, of course, free to use whatever method you wish.
have some WebViewExtras alternative to B4J ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you need webviewextras (with b4a) because i chose to show the device listing as a javascript alert. to do that you need webviewextras' chromeclient. you don't have to show the devices with an alert. you could just as easily show them in the body of the test page.

for example, you create a <div> element in the body and in the init() function, you populate the <div> with the list. do you do any html or js coding? you're going to have to do a lot once you get into cameras and microphones.

i'm attaching an example. the forum does not accept .html files, so i had to change the name to devices.txt. it's the same as the devices.html file i attached previously but it doesn't use a javascript alert. so you don't need webviewextras anywhere.

now for the bad news: the webkit that runs with b4j appears not to support camera or microphone. i don't work much with b4j, so i don't know if you can extend webkit as easily as android's webview can be extended. maybe someone else does. my devices test file will list the devices in a webview on an android device and on a pc browser, AND it does work with b4j's webkit webview, BUT only to indicate that support for camera/microphone is not available. i'm also attaching a screen capture of what b4j's webview shows. sorry.

EDIT: i have just read that you will see a similar not supported message if http is used instead of https. so, unless you are running a secure server on your pc, there is no way to load the test with https. again, sorry.

EDIT 2: if you look here you will see it looks like a big deal to get all the features of webkit to run on windows.
 

Attachments

  • devices.txt
    852 bytes · Views: 178
  • devices2.png
    devices2.png
    3.4 KB · Views: 160
Last edited:
Upvote 0
Top