Hello
Has tried to create a version's secure handling of 'Audio focus' media has stuck.
Can anyone help ?.
Has tried to create a version's secure handling of 'Audio focus' media has stuck.
Can anyone help ?.
B4X:
Sub requestFocus(request As Boolean) As Boolean
Try
jo.InitializeContext
jo = jo.RunMethod("getSystemService", Array("audio"))
event = jo.CreateEventFromUI("android.media.AudioManager.OnAudioFocusChangeListener", "audio", Null)
Dim p As Phone
If p.SdkVersion <= 25 Then
If request = True Then
If jo.RunMethod("requestAudioFocus", Array (event, p.VOLUME_MUSIC, 2)) = 1 Then Return True
Else
jo.RunMethod("abandonAudioFocus", Array (event, p.VOLUME_MUSIC, 2))
End If
Else
If request = True Then
If jo.RunMethod("requestAudioFocus", Array (event, p.VOLUME_MUSIC, 2)) = 1 Then Return True
Else
jo.RunMethod("abandonAudioFocusRequest", Array(event, p.VOLUME_MUSIC, 2))
End If
End If
Return False
Catch
Log("Sub requestFocus " & LastException)
Return False
End Try
End Sub
Sub audio_Event (MethodName As String, Args() As Object) As Object
Log("Methodname = " & MethodName)
If MethodName = "onAudioFocusChange" Then
mpStop ' mp.stop ( MediaPlayerStream)
End If
Return Null
End Sub