[FREE] BgRadio: Foreground Streaming Radio Service

[FREE] BgRadio: Foreground Streaming Radio Service with Dynamic BigText Notification

:pushpin: Overview

BgRadio is a high-performance, non-visible component designed for playing internet radio and multimedia audio streams seamlessly in the background. Built on top of a pure Android native MediaPlayer with 100% zero external library dependencies, it is perfectly tailored for Niotron and MIT App Inventor. [1, 2]

It features an intelligent Bypass & Fast HEAD Streaming Resolver that routes standard audio URLs directly to the hardware decoder while parsing complex playlist formats (.m3u, .m3u8, .pls, .asx) asynchronously with redirect tracking and Session Cookie persistence. It also includes an ESP32-aligned worldwide radio directory lookup engine and an advanced Android BigTextStyle notification manager.

  • Latest Version: 10.0

  • Price: Free

  • Permissions Required: INTERNET, FOREGROUND_SERVICE, FOREGROUND_SERVICE_MEDIA_PLAYBACK, POST_NOTIFICATIONS


:package: Designer Properties

Property Type Description
AvailableCountries YailList (Read-only) Returns a complete pre-defined list of global country codes (e.g., TW, US, JP, ALL).
AvailableGenres YailList (Read-only) Returns a comprehensive pre-defined list of main radio genres and music styles (e.g., Pop, Jazz, Classical).
PlaybackState String (Read-only) Actively fetches the real-time playback state (Playing, Buffering, Stopped, Timeout Reconnecting, etc.).
LastPlayedUrl String (Read-only) Retrieves the last successfully played audio stream URL from SharedPreferences for effortless persistent resume capability.

:brick: Component Blocks & Methods

:rocket: Functions / Methods

  • RegisterBroadcast()
    Manually activates and registers the global BroadcastReceiver to handle background playback and search intents safely across Android 13 and 14+ (using numerical exporting flag 2). [1]

    regborcast

  • UnregisterBroadcast()
    Unregisters the global broadcast listener to free up device system memory when the app is no longer in use. [1]

    unregborcast

  • BroadcastPlay(String streamUrl)
    Triggers high-priority background service execution to play the specified audio stream. Smart Auto-Resume Feature: If an empty text "" is passed, it automatically retrieves the LastPlayedUrl from internal hardware persistence for instant resume. [1]

  • BroadcastStop()
    Instructs the background foreground service to safely stop audio playback, release decoding resources, and terminate the notification drawer card. [1]

    top

  • BroadcastSearchStations(String country, String genre)
    Asynchronously queries the distributed worldwide Radio-Browser API to dynamically filter, parse, and return matching stations. [1]

  • SetNotificationPayload(String topic, String message)
    Configures the Android BigText Notification Style data. Allows developers to push multi-line, long-text status payloads (such as real-time program titles or descriptions) directly to the system drawer. [1]

:satellite_antenna: Events

  • OnStatusChanged(String status)
    Triggered dynamically when the internal playback loop updates. Expected outputs: Playing, Buffering, Stopped, Timeout Reconnecting, or Connect Error: .... [1]

  • OnRadioListReceived(String jsonList)
    Triggered when the worldwide background directory search finishes. It automatically rejects .m3u8 video packets, isolates low-bitrate MP3/AAC streams (<192kbps), and returns a clean, structured JSON array string. [1]

  • OnDebugLog(String logMessage)
    Passes real-time execution steps, redirect paths (301/302/307/308 tracking), and file parsing headers from the Streaming Resolver engine for advanced logging. [1]


:artist_palette: Recommended Blocks Implementation (How-To)

  1. Initialization & Lifecycle Safety:
    Always invoke BgRadio1.RegisterBroadcast in your Screen1.Initialize block. This forces the system broadcast mechanism awake and guarantees reliable background play operations even after an Android system freeze or memory cleaning event.

  2. One-Tap Dynamic Toggle Button:
    Utilize an if-else statement inside a Button click block:

    • If BgRadio1.PlaybackState equals Playing, then invoke BgRadio1.BroadcastStop and update button layout to a "Play" icon.

    • Else, invoke BgRadio1.BroadcastPlay with an empty string "" to immediately resume the user's favorite radio station via auto-persistence hardware lookup.

  3. Advanced Display Payloads:
    Combine the SetNotificationPayload function right before firing up a playlist. Feed a long text string into the message parameter (e.g., "Now Playing: Jazz Midnight Special - Curated Chillout Lofi Beats"). The drawer notification card will gracefully scale to display the entire string without annoying truncations.


:link: Sourcing & Downloads

  • Developer / Contact: [halin / miracle ho]

  • Compiled Extension File (.aix): BgRadio.aix (50.3 KB)

  • Sample Project File (.aia): bgradio_ext.aia (59.4 KB)

Feedback, suggestions, and log reports from your OnDebugLog events are highly welcome below!

:globe_with_meridians: (GitHub Link) This extension is 100% free. You can report issues, track redirect performance logs, or fork the repository directly on GitHub: :link: **GitHub Repository:** `https://github.com` *(Feel free to give it a :star: Star if it helps your multimedia streaming projects!)* ---


1 Like

Hi, I tried the .aia file with the companion but when I choose the radio station I can't hear anything, also the button remains in STOP even if I press it again.

It work just if i build the app

my device is a samsung S23ultra android 16 ui 8.5

I believe this is the expected behavior, as the companion app lacks the necessary permissions.

2 Likes

Application video

No permissions need to be set.:grinning_face_with_smiling_eyes:

Yes, because the companion app does not offer a foreground service

Taifun

2 Likes

:thinking:
Of course, these permissions: FOREGROUND_SERVICE , FOREGROUND_SERVICE_MEDIA_PLAYBACK , POST_NOTIFICATIONS must be declared in the Manifest. But the Companion app doesn't do it.

2 Likes