Hello !
I don't understand why the following code works on my smartphone with B4A Bridge, the sound is correctly played. When I compile the application in release mode and run it, the app works but there is no sound! This must be due to ExoPlayer. Could it be a permission issue? The link to the stream is good and works. I just have this problem when I open the app installed on my smartphone. Thanks for your help.
Manifest :
I don't understand why the following code works on my smartphone with B4A Bridge, the sound is correctly played. When I compile the application in release mode and run it, the app works but there is no sound! This must be due to ExoPlayer. Could it be a permission issue? The link to the stream is good and works. I just have this problem when I open the app installed on my smartphone. Thanks for your help.
My code:
#Region Project Attributes
#ApplicationLabel: Radio Les Floralies - RLF2
#VersionCode: 4
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
'#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: True
#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
Private MonTimer As Timer
Private Lecteur As SimpleExoPlayer
Private OldIntent As Intent
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private Bouton_jouer_stop As Button
Private WebView_principal As WebView
Private Label_message As Label
Private ImageView1 As ImageView
Private ImageView2 As ImageView
Private ImageView3 As ImageView
Private CONST VERSION_APPLI As String = "Version 2.0"
Private Const URL_SITE As String = "https://www.lesfloralies.info"
Private Const MAIL_CONTACT As String = "[email protected]"
Private Const URL1_WEBVIEW As String = "https://www.lesfloralies.info/programme/html/encours_android.html"
Private Const URL2_WEBVIEW As String = "https://www.lesfloralies.info/flash/"
Private Const URL3_WEBVIEW As String = "https://lesfloralies.info/podcasts/liste_podcasts.php"
Private Const URL4_WEBVIEW As String = "https://lesfloralies.info/"
Private Const URL_ECOUTE As String = "http://lesfloralies.ovh:8000/floralies.ogg"
Private Const PHRASE_ECOUTER_LA_RADIO As String = " Écouter"
Private Const PHRASE_SLOGAN As String = "Un moment de flânerie"
Private Const PHRASE_ARRETER_ECOUTE As String = " Arrêter"
Private Const CONTENU_ENCOURS As Int = 1
Private Const CONTENU_PODCAST As Int = 2
Private Const CONTENU_FLASH As Int = 3
Private Const CONTENU_SITE As Int = 4
Private Contenu_affiche As Int
End Sub
Sub ImageView1_Click
Afficher_site
End Sub
Sub ImageView2_Click
Afficher_flash
End Sub
Sub ImageView3_Click
Afficher_podcasts
End Sub
Sub Afficher_site
Stop
WebView_principal.LoadUrl (URL4_WEBVIEW)
Label_message.Text = "Le site de la webradio"
Contenu_affiche = CONTENU_SITE
End Sub
Sub Afficher_en_cours
WebView_principal.LoadUrl (URL1_WEBVIEW)
Label_message.Text = "En cours de diffusion..."
Contenu_affiche = CONTENU_ENCOURS
End Sub
Sub Afficher_flash
Stop
WebView_principal.LoadUrl (URL2_WEBVIEW)
Label_message.Text = "Le flash du jour"
Contenu_affiche = CONTENU_FLASH
End Sub
Sub Afficher_podcasts
Stop
WebView_principal.LoadUrl (URL3_WEBVIEW)
Label_message.Text = "Les podcasts"
Contenu_affiche = CONTENU_PODCAST
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout_principal")
If FirstTime Then
MonTimer.Initialize("Timer", 1000)
Lecteur.Initialize("Lecteur")
Label_message.Text = PHRASE_SLOGAN
End If
MonTimer.Enabled = True
Label_message.Text = "Touchez ci-dessus !"
Label_message.Text = "Bonjour."
Activity.AddMenuItem ("En cours de diffusion","Menu_encours")
Activity.AddMenuItem ("Le Flash du jour","Menu_flash")
Activity.AddMenuItem ("Les Podcasts","Menu_podcasts")
Activity.AddMenuItem ("À propos","Menu_a_propos")
Activity.AddMenuItem ("Quitter","Menu_quitter")
ImageView1.Bitmap = LoadBitmap(File.DirAssets, "radio1.png")
ImageView2.Bitmap = LoadBitmap(File.DirAssets, "radio2.png")
ImageView3.Bitmap = LoadBitmap(File.DirAssets, "radio3.png")
Afficher_en_cours
Lecteur.Prepare(Lecteur.CreateUriSource (URL_ECOUTE))
End Sub
Sub Menu_encours_Click
Afficher_en_cours
End Sub
Sub Menu_flash_Click
Afficher_flash
End Sub
Sub Menu_podcasts_Click
Afficher_podcasts
End Sub
Sub Menu_quitter_Click
Quitter
End Sub
Sub Menu_a_propos_Click
Xui.MsgboxAsync("Radio les floralies - RLF2" & Chr(13) & Chr(10) & "L'application Android" & Chr(13) & Chr(10) & URL_SITE & Chr(13) & Chr(10) & MAIL_CONTACT & Chr(13) & Chr(10) & VERSION_APPLI , "À Propos")
End Sub
Sub Timer_Tick
Select Contenu_affiche
Case CONTENU_ENCOURS
Afficher_en_cours ' rafraichit la page
Case CONTENU_PODCAST
'Afficher_podcasts ' affiche la page des podcasts
Case CONTENU_FLASH
' ne fait rien pour ne pas rafraichir la page ! Technologie Ajax
Case CONTENU_SITE
' ne fait rien pour ne pas rafraichir la page !
End Select
End Sub
Sub Activity_Resume
Dim in As Intent = Activity.GetStartingIntent
If in.IsInitialized And in <> OldIntent Then
OldIntent = in
If in.HasExtra("Notification_Tag") Then
Log("Activity started from notification. Tag: " & in.GetExtra("Notification_Tag"))
End If
End If
End Sub
Sub Lecteur_Ready
Jouer
End Sub
Sub Lecteur_Error (Message As String)
Xui.MsgboxAsync("Problème, veuillez relancer l'écoute","Oups! '" + Message + "' !")
'Log("Error: " & ErrorCode & ", " & ExtraData)
End Sub
Sub Bouton_jouer_stop_Click
Afficher_en_cours
If Lecteur.IsPlaying = False Then
Jouer
Else
Stop
End If
End Sub
Public Sub Jouer
If Lecteur.IsPlaying = False Then
Lecteur.Play
Lecteur.Volume=1
Label_message.Text = PHRASE_SLOGAN
Bouton_jouer_stop.Text = Chr(0xF04D) & PHRASE_ARRETER_ECOUTE
End If
End Sub
Public Sub Stop
If Lecteur.IsPlaying = True Then
Lecteur.Pause
Bouton_jouer_stop.Text = Chr(0xF04B) & PHRASE_ECOUTER_LA_RADIO
Label_message.Text = "Bonne écoute !"
End If
End Sub
Public Sub Quitter
Bouton_jouer_stop.Text = Chr(0xF04B) & PHRASE_ECOUTER_LA_RADIO
Label_message.Text = ""
Lecteur.Release
Activity.Finish
End Sub
Sub Demander_quitter
Msgbox2Async ("Voulez-vous quitter l'application ?","Radio Les Floralies","Oui","","Non",Null, True)
Wait for MsgBox_result (Result As Int)
If Result = DialogResponse.POSITIVE Then
Quitter
End If
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
Demander_quitter
Return True
Else
Return False
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Manifest :
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.ACCESS_NETWORK_STATE)
CreateResourceFromFile(Macro, Core.NetworkClearText)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.LightTheme)
'End of default text.