Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Cushty's avatar

useContext vs Inertia shared data

Hi I am making a meditation app to practice my learning, I am a bit confused about whether to use context or Inertia shared data to access the audio files. I want to make the audio player part of the default layout so the audio will continue playing on every page even if the user moves off the show page and is browsing the app.

Inertia shared data seems to be the easiest to implement but will using it slow down the application? What would you guys use? Thanks

0 likes
6 replies
gych's avatar

Do you want to set the audio file from the server or client side?

I've previously build a similar audio player and didn't need to use shared data. The audio player was build as a Vue plugin and the playing audio was set on the client side.

martinbean's avatar

@cushty The Inertia docs cover this exact scenario. What you’re looking for is persistent layouts: https://inertiajs.com/pages#persistent-layouts

For example, maybe you have an audio player on a podcast website that you want to continue playing as users navigate the site.

I use this in the admin panel of my video platform so that users can continue navigation around their admin panel whilst a video upload is in progress.

Cushty's avatar
Level 4

Thanks for the reply but I am getting really stuck been trying for a week. #skillIssue I need to pass the audio as props to the audio player component that is currently on a layout component, the issue I am having is the logic to map through the audios for a specific mediation is the show controller. I cant work out if I need to use the shared data or a context to allow a click on show page to play the audio player but keep playing whilst navigating the app.

Hipw you can point me in the right direction, thanks

gych's avatar

@Cushty Did you already try to use a persistent layout like @martinbean adivsed ?

First make sure that the audio player keeps playing after you switch pages. When you got that part working you can focus on sending the audio to the player .

1 like
martinbean's avatar

Hipw you can point me in the right direction, thanks

@Cushty I already did. I pointed you to the Inertia docs which gives an example of your exact use case.

Cushty's avatar
Level 4

Hi yes I got the audio playing even when moving around the app, I first used jefferys podcast player embed, then once that was working swapped it out for the actual audio from the model, but I had to use a context to be able to pick up the right audio for the individual meditation. Got it working with the help of copilot chat, but the issue now is pausing the audio etc.

I have a feeling maybe using inertia shared would be better to use? As it getting quite confusing using context, useeffect and state to play, pause, play a new audio if going to another meditation.

My issue now is if I got to the show page I click play, it works I go to homepage audio keeps playing, but if I go to another meditation and click play, 1 click loads the audio, then I have to click again to actually play it.

I just have a feeling there may be an easier way, thanks

Please or to participate in this conversation.