[Need help] How to Pause Radio app

robife

Member
Licensed User
Longtime User
Hi guys I made some very simple radio app but need help with one thing

I need the radio app to pause(sound), when Incoming call.

B4X:
#Region Module Attributes
    #FullScreen: True
    #IncludeTitle: False
    #ApplicationLabel: Radio Prime Halden
    #VersionCode: 1
    #VersionName: 
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Url As String
    Dim b As MediaPlayerStream
    Dim Label1 As Label
    'Dim WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
Activity.LoadLayout("view")
'WebView1.LoadUrl("http://www2.radioprime.com/webradio/index.php?stasjon=halden")
If FirstTime Then
        b.Initialize("b")
    End If
    b.Load("http://primestream.monsternett.no:8000/prime.mp3")
    
    Label1.Width = 100%x

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub Button1_Click
    
    b.Play
End Sub

Sub Button2_Click
    b.Pause
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
    If KeyCode = KeyCodes.KEYCODE_BACK Then
        If Msgbox2("Vil du lukke programmet?", "", "Ja", "Avbryte", "Nei", Null) = DialogResponse.POSITIVE Then
          '  Return False
 ExitApplication 'App is exiting
        Else
            Return True
        End If
    End If
End Sub

Test my app here
http://www.b4x.com/forum/test-my-app/26229-test-my-first-radio-online.html
 

robife

Member
Licensed User
Longtime User
Thanks again NJDude

I was searching and reading, but still nave not luck finding something working

I try with this

B4X:
Sub PhoneStateChanged (State As String, IncomingNumber As String, Intent As Intent)
'use parameters:OFFHOOK or RINGING
If State="RINGING" Then
b.Pause
End If
    End Sub


B4X:
Sub Service_Create
    'PE.InitializeWithPhoneState("PE",PhoneId)
    PE.Initialize("PE")
End Sub
 
Upvote 0

robife

Member
Licensed User
Longtime User
NJ Dude now when phone display goes to lock/sleep radio app stop playing music and wont start again
Do you know what is wrong?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
If you are using the code exactly as the example I posted that's expected, I am stopping the playback when the app gets paused, you will have to adjust the code to your needs, you can remove the "MP.Stop" in Activity_Pause, but you will have to add a way to stop the playback (using a button, etc)

The sample was just a very basic code to show the feature you required.
 
Upvote 0

desof

Well-Known Member
Licensed User
Longtime User
Hello friend can share the radio code I am needing just that I can not access the original post.

thanks
 
Upvote 0
Top