Background Audio Player on OutSystems Mobile App
Requirements
An audio participant that may proceed taking part in within the background (whether or not the customers exits the app or navigates to completely different screens throughout the app)
Problem
For OutSystems Mobile App, React is used for its frontend. For React builders, one would in all probability develop in a means the place the audio participant element will probably be positioned on the high degree, in order that when the app traverses from web page to web page, the audio participant is not going to be re-rendered.
In OutSystems, one would consider putting the audio participant element within the structure internet block or menu (navigation) internet block, the place it can almost definitely be the frequent block used by all of the screens. However, the entire web page (Layout Web Block and its parts inside) re-renders with every display transition. Thus, the audio participant additionally re-renders and the audio stops taking part in when the display transits to a different.
Compromise
Initially I used to be pondering of proposing a compromise to the stakeholders and requested if it was acceptable to have the audio "pause" because the display transits and the audio "proceed" to play when the brand new display transits in. This will imply the app will in all probability need to retailer the final performed time within the localStorage within the On Destroy occasion (when the transition to the brand new Screen ends). Then within the new display’s On Render Event, retrieve the final performed time from the localStorage, search to the final performed time after which play the audio.
Solution
As I used to be testing the "compromise", I remembered and that the React root is the "top-level" <div> and never <physique>. Then, it was clear to me that if I can place the Audio Player exterior of the React root, which might at all times re-render, the Audio Player can carry on taking part in so so long as the web page doesn’t refresh.
The root React ingredient in OutSystems is <div id="reactContainer">. You can in all probability put within the following Javascript within the OnApplicationReady occasion to append the Audio Player ingredient within the save degree as <div id="reactContainer"> (append to <physique>).
var jwPlayerComponent = doc.createElement('div')
jwPlayerComponent.id = 'jw-player';
doc.getElementsByTagName('physique')[0].appendChild(jwPlayerComponent);
var jwPlayer = jwplayer('jw-player');
jwPlayer.setup({
sources: [
{file: "https://domain.com/playlist.m3u8"}
]
})
Change the initialisation codes based on your Audio Player’s necessities. As JWPlayer permits the retrieval of the occasion by jwplayer('jw-player') at any location, I can simply name it once more to alter the supply or name its strategies (play, pause, and so forth.) If your participant does present such a performance, you might have to incorporate a script to retailer the audio participant occasion to a worldwide variable.
TODO
-
Image and Diagrams to clarify the steps higher.
-
Sample OutSystems OML file.
HI-FI News
by way of DEV Community https://dev.to
April 30, 2024 at 04:52PM
-
Product on sale
Audiophile Vinyl Records Cleaning BundleOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Product on sale
Easy Start Vinyl Records Cleaning KitOriginal price was: €69.90.€59.90Current price is: €59.90. incl. VAT -
Vinyl Records Cleaner Easy Groove Concentrate€34.95 incl. VAT -
Easy Groove Super Set€199.00 incl. VAT -
Easy Groove Enzycaster – vinyl records prewash cleaner€34.95 incl. VAT -
Easy Groove Extreme MK. II- vinyl records prewash cleaner€45.00 incl. VAT -
Vinyl Records Cleaner – Easy Groove Virgin Concentrate€35.00 incl. VAT -
Easy Groove Spray&Wipe vinyl records cleaner€34.95 incl. VAT








