Android Question Phone volume buttons doesn't work in all activities

serjio

Member
Licensed User
Hi, I'm working on App with some activities and a background music that start from MediaPlayer in Main Activity_Create.
The problem is that the music volume can't be set in main activity by volume phone buttons while it works in all other activitie.
Furthermore phone volume buttons doesn't work in an activity that contains webview and where I declared another MediaPlayer with a different audio.
I've read some posts but nothing.

Thanks
 

serjio

Member
Licensed User
Thanks for interest Erel.
Nothing has changed neither in Main and webview activity.
I've declared variables first in globals, then process globals just to try all.
The problem exist in emulator and my phisical phone.

This is my code for play audio in Activity_create

B4X:
Public audioBg As MediaPlayer  'process globals
audioBg.Initialize2("audioBg")
audioBg.Load(File.DirAssets, "app-bg.mp3")
audioBg.Looping = True
audioBg.SetVolume(0.2 , 0.2)
 
Last edited:
Upvote 0

serjio

Member
Licensed User
I've noticed that volume buttons doesn't work in the activity where I declared and initialized the MediaPlayer type to load a bg sound. Same in the Activity that contains only a webview
 
Upvote 0

serjio

Member
Licensed User
Yes, I've tried all without results.
Because the problem is only in two activities I've compared with more attention both codes and finded that the problem is caused by following code:
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
        If KeyCode = KeyCodes.KEYCODE_BACK Then
            audioBg.Stop
            Activity.Finish
        End If
        Return True
End Sub

Disabling this audio volume buttons works properly.
It's the first time that I program software from scratch, maybe I wrote this not in the right way.
There's a way to prevent this in Activity_KeyPress?
 
Upvote 0
Top