Android Question WebView locks up when playing local audio

cbanks

Active Member
Licensed User
Longtime User
I have a link in a webview. When I tap on the link to play the audio that the links points to (a local mp3 on the device), the webview locks up and I can't scroll or do anything with the webview until the audio gets done playing. any ideas? I use MediaPlayer to play the audio.

It used to work where users could listen to an mp3 while still viewing web pages in my app.
 
Last edited:

cbanks

Active Member
Licensed User
Longtime User
I don't understand the relation between MediaPlayer and WebView. Are you handling the OverrideUrl event?

Yes, I'm telling it to play with MediaPlayer in the overrideurl event so that it plays in the background.

As soon as I use the Player.Load command the webview becomes unresponsive. I don't even have to call the player.play command.

Same thing happens if I play the local audio using mediaplayerstream as well.

I have a hunch that this started happening when I went to ajwebkit (DefaultWebViewClient1)

Below is stuff related to my webview earlier in the code:

B4X:
Dim FlingableWebView1 As FlingableWebView
Dim DefaultWebViewClient1 As DefaultWebViewClient
Dim WebViewExtras1 As WebViewExtras
Dim wvXtender As WebViewXtender

DefaultWebViewClient1.Initialize("FlingableWebView1")
DefaultWebViewClient2.Initialize("FlingableWebView2")

FlingableWebView1.SetWebViewClient(DefaultWebViewClient1)
FlingableWebView2.SetWebViewClient(DefaultWebViewClient2)

FlingableWebView1.Initialize("FlingableWebView1")
WebViewExtras1.addJavascriptInterface(FlingableWebView1, "B4A")
Activity.AddView(FlingableWebView1, 0, 120, 100%x, 100%y-120)
Reflector1.Target=FlingableWebView1

FlingableWebView1.JavaScriptEnabled = True
FlingableWebView1.ZoomEnabled = True
 
Last edited:
Upvote 0

cbanks

Active Member
Licensed User
Longtime User
I found out that if I remove a msgbox2 in the override sub code before it tries to play the local mp3, then the webview is still responsive. But I want to ask the user a question before the audio plays and wait for their response before playing the audio, but then the webview becomes unresponsive.

Any ideas why this causes a problem? It used to work just fine asking a question and waiting for a response before playing the audio.

Would the msgbox2async solve this problem? If so what is the code for that?

Currently the msgbox2 code looks like this:
B4X:
result = Msgbox2("Question?", "Select Option", "Continuous", "No", "Repeat", Null)

Below is my code to change to msgbox2async. What else do I need to add to my code to make it work?

B4X:
Msgbox2Async("Question?", "Selection Options", "Continuous", "No", "Repeat", Null, False)
Wait For MsgBox_Result (result As Int)

It threw an error on compile: Resumable subs return type must be ResumableSub (or none). So I changed As Boolean at the end of the override sub to As ResumableSub

B4X:
Sub FlingableWebView1_OverrideUrl(FlingableWebView As FlingableWebView, url As String) As Boolean

Then when I compile it throws this error:

error: code too large
public void resume(BA ba, Object[] result) throws Exception{
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

How do I fix that?

I have msgbox2's in other parts of my app and they work fine, just locks up webview when used in the webview override sub.
 
Last edited:
Upvote 0
Top