MAUI: Keep audio playing when navigating to a new page
Sreejith Sreenivasan
941
Reputation points
I am using Webview
for playing audio and when I navigate to a new page the audio stops playing. I want to play the audio in background when navigating to new pages, or switching app or locking device.
My Code:
<WebView
x:Name="audio_webview"
BackgroundColor="Transparent"
Navigated="OnWebViewNavigated"
HorizontalOptions="FillAndExpand"
VerticalOptions="CenterAndExpand" >
<WebView.HeightRequest>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>80</OnIdiom.Phone>
<OnIdiom.Tablet>120</OnIdiom.Tablet>
<OnIdiom.Desktop>80</OnIdiom.Desktop>
</OnIdiom>
</WebView.HeightRequest>
<WebView.WidthRequest>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Phone>420</OnIdiom.Phone>
<OnIdiom.Tablet>630</OnIdiom.Tablet>
<OnIdiom.Desktop>420</OnIdiom.Desktop>
</OnIdiom>
</WebView.WidthRequest>
</WebView>
audio_webview.Source = audioUrl;
When I navigate to a new page I am getting below messages in the output box:
11:04:37:012 [AAudio] AAudioStream_requestStop(s#1) called
11:04:37:012 [AAudio] AAudioStream_close(s#1) called ---------------
11:04:37:012 [AAudioStream] setState(s#1) from 10 to 11
11:04:37:012 [AudioTrack] stop(portId:2774, sessionId:48889): 0xb400006eb01c3f40, prior state:STATE_STOPPED
11:04:37:012 [AudioTrackShared] this(0xb400006e500b8550), mCblk(0x6d7fcdc000), front(311736), mIsOut 1, interrupt() FUTEX_WAKE
11:04:37:012 [AudioTrack] requestExitAndWait start
11:04:37:012 [AudioTrack] requestExitAndWait end
11:04:37:012 [AudioTrack] stopAndJoinCallbacks(2774) done
11:04:37:012 [AudioTrack] ~AudioTrack(2774): 0xb400006eb01c3f40
11:04:37:072 [AudioTrack] getpackName client name com.companyname.appname(24146)
11:04:37:072 [AudioTrack] stop(portId:2774, sessionId:48889): 0xb400006eb01c3f40, prior state:STATE_STOPPED
11:04:37:072 [AudioTrack] stopAndJoinCallbacks(2774) done
11:04:37:072 [AAudioStream] setState(s#1) from 11 to 12
11:04:37:072 [AAudioStream] ~AudioStream(s#1) mPlayerBase strongCount = 2
11:04:37:072 [AAudio] AAudioStream_close(s#1) returned 0 ---------
I want to play the audio in background without pausing when opening new pages. This feature is working fine on iOS platform, but in android only the audio is pausing.
Sign in to answer