Android Question Play audio file from HTML

Avansys

Member
Licensed User
Longtime User
WebView does not play an audio file inserted in a HTML. How can I do?

I have a html file with the following code:
HTML:
<script>
  function playAudio($audio)
  {
      playAudio.playAudio($audio);
  }
</script>

<span onclick="playAudio('1.mp3');">A</span>

The audio file sounds when I run the HTML on PC. However, My app loads the HTML file but does not play the audio.
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
<script>
  function playAudio(audio)
  {
      playAudio.playAudio(audio);
  }
</script>

should work... You dont need $... Copied the code from an PHP-Example?
 
Upvote 0

Avansys

Member
Licensed User
Longtime User
Thank you, I already solved my problem.

I attached a Javascript namespace to WebView and put onclick="NameSpace.CallSub('FunctionName', true, 'Parameters');"

Hope this help anyone trying to communicate javascript with Basic 4 Android functions.

However, I've another doubt, what is the best solution to download audio files from remote server to my app? I tried to base64 encode it via XML and the parse it in my app but I got out of memory messages.
 
Upvote 0
Top