Dear forum experts,
I have some programming experience, but I'm new to B4A and programming for Android.
I have a quite simple app. It listens to UDP and whenever it receives ANYTHING (for the moment), it starts an mp3 with Media Player.
This works fine, but it misses the play trigger with screen off. I would GUESS that it's UDP stopping to listen and not the Media Player being
unable to start playing. While this might be the standard setting and useful for many cases, it's just a waste of battery to keep the screen
on in my case.
Is there any setting, permission or other way to make this work with screen off?
I have some programming experience, but I'm new to B4A and programming for Android.
I have a quite simple app. It listens to UDP and whenever it receives ANYTHING (for the moment), it starts an mp3 with Media Player.
This works fine, but it misses the play trigger with screen off. I would GUESS that it's UDP stopping to listen and not the Media Player being
unable to start playing. While this might be the standard setting and useful for many cases, it's just a waste of battery to keep the screen
on in my case.
Is there any setting, permission or other way to make this work with screen off?
B4X:
#Region Project Attributes
#ApplicationLabel: UDP_Player1
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Dim UDPSocket1 As UDPSocket
Dim MediaPlayer1 As MediaPlayer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
If FirstTime Then
UDPSocket1.Initialize("UDP", 12101, 8000)
MediaPlayer1.Initialize( )
MediaPlayer1.Load(File.DirAssets,"flash.mp3")
End If
End Sub
Sub Activity_Resume
'MediaPlayer1.Play
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'If MediaPlayer1.IsPlaying Then MediaPlayer1.Pause
End Sub
Sub UDP_PacketArrived (Packet As UDPPacket)
Dim msg As String
'msg = BytesToString(Packet.Data, Packet.Offset, Packet.Length, "UTF8")
'Msgbox("Message received: " & msg, "")
MediaPlayer1.Play
End Sub