📻 WebView Radio Stream Player

Thanks, will try with <iframe> later.

Doesn't work, Chrome blocked that too. To play sound, user must interact with the web page (touch/click), you cannot program it (e.g. with javascript).

Isn't there some permission to ask for autoplay to work? Strange that the original WebView browser has autoplay.

If calling a url directly into the webview, it will play automatically. Any kind of web page that has a sound source will not play unless the user interacts with the webpage to say "yes, I want sound"

This stops all websites from playing sound automatically in their ads etc. You can autoplay a sound file, but it has to be muted, the user then has to unmute the playback by interacting with the web page.

<audio id="radio" autoplay muted>
		<source src="http://stream.live.vc.bbcmedia.co.uk/bbc_radio_two">
	Your browser does not support the audio element.
</audio>

<button id="unmuteButton">UNMUTE</button>

<script>
var radio = document.getElementById('radio');
unmuteButton.addEventListener('click', function() {
radio.muted = false;
});
</script>

So unmute or play can't be called from outside? So Google thinks for us again and knows better what people want. And it would be enough for them to add some permission so that the user can decide what he wants to play automatically and what not...

-- Steve

When I first did it on Android 2.4, this problem seemed very minimal. It wasn't a problem. But as android versions got higher, there were more and more problems. Now I can't use it because of this freezing problem.
But I didn't bother to improve. I made a radio website and it serves from there. It can be used with an internet browser.

could it be like this?

http://mikrobotikradyo.tk/

I've lost a bit of an overview of what this is actually about and where exactly the problems are and on which Android versions they are relevant (they can occur).

As far as I have tested, streams can also be played continuously with the player component if you accept a certain buffer time and use a Foreground service (from Android 23 to prevent Doze mode).

Try this one:

I have noticed that some radio stations are temporarily unavailable (neither via the app nor via my computer (Chrome / Firefox). The app tries to connect (buffer) the radio station for 15 seconds, then it is aborted and recommended to try another.

The app can also be operated from the background and/or the locked screen. The stream shouldn't break off even in idle mode.

As I already said, since the introduction of Doze (Android 6, API 23):

Speaking of the freezing issue, what we meant was that when we use the built-in ai2 player to play a stream, the player freezes the entire app while buffering. Because caching is done in the main app thread. This gives a bad impression, especially when buffering takes a long time.

I see that he used a buffering notification in his app. This is some solution.

I researched the matter and tested several ways. It can be concluded that when the page with the Audio component is displayed in CustomWebView in app inventor, it is possible to automatically play the sound without user intervention. It is enough to intervene in the app inventor code, for example, in the "PageLoaded" block with CustomWebView". Just use setWebViewString to call click on the button that starts playing in java script.

This app implements it:

  • click the magnifying glass and search for stations
  • click "Szukaj"
  • playing the first station will start automatically
  • add several stations to favorites by clicking on the star
  • click on the heart to go to favorites
  • you can play your favorites
  • after closing and opening the app, 1 item from the list of favorites will be played

App made in 90% in javascript. App Inventor blocks mainly handle notification, errors, and metadata.


1 Like

Pixel 4XL / Android 13

After I had to search for some time and finally found and clicked this tiny button ("szukaj" = search?), finally the search process started and then this appeared:

Most stations don't play and when the app is exited the sound doesn't stop. You have to uninstall the app or clear Storage/cache in the app settings.

... and unfortunately this trick doesn't work on Android 13 (anymore). So that when you click on the notification, a dummy screen is opened, which is then immediately closed again. This works perfectly on older Android versions (but on Android 13 the screen is not brought back to the foreground from the background).

grafik

How do you close the app? double click back? Are you killing it by removing it from the task list?

I've tried all of them.

This is strange, because when closing, clicking back stops the player, so the sound should not be heard. On kill, however, an onDestroy event would be needed. Your sample app on my android 9 is also still playing after killing the app.

Unfortunately, I do not have android 13. How does it look on android 13? Nothing opens at all? Do you know any solution for this for android 13? I saw you have the LiveCycle extension, is it needed on newer androids? Since on Android 9 I didn't notice the need to use it with the MediaNotification extension.

Yes. You must get the screen manually from the background (via task manager).

Unfortunately not yet, but I haven't tried much either. Although I use this myself in my apps and actually need a solution for it.

But what could a solution look like that does not consist of bringing the current screen back into the foreground. Restarting the app cannot be a solution, because the music may be supposed to continue at a certain point.

You also get a strange view of the search engine. There should be 3 text boxes...I understand the differences between android versions but I think something done in java script should display the same on different androids.

Looks like it didn't come out all the way. But the search interface needs improvement, it's a draft. I think that I will choose a country using a list.