Android Question The music ends with dark screen

Giusy

Active Member
Licensed User
Hi, my program plays sequenced music automatically.
but when the video gets darker the song in progress is played to the last and the program stops at the point without loading the next song. How can I overcome this inconvenience?
Thanks
 

Giusy

Active Member
Licensed User
Hi @Erel this is a very small summary of my program

Dim sp As MediaPlayer
sp.Initialize2("sp")
sp.load(File.DirAssets,"xxxxxxxx001")
sp.PLAY


then the file becomes xxxxxxxxx002
xxxxxxxxx003
xxxxxxxxx004 .....


With this instructions the screen always remains illuminated:

Dim onscreen As PhoneWakeStateSub
Activity_Resume
onscreen.keepalive(True)
End Sub

Sub Activity_Pause (UserClosed As Boolean)
onscreen.releasekeepalive
End Sub

But if the user press Home or other the program, at the end of song, stopped

Thanks
 
Upvote 0

Giusy

Active Member
Licensed User
@Geezer Unfortunately sticky service is for me only a word. :(

I do not know all the possibilities of b4a as I use it for a month.

Please, write me a few lines of the program so that I can understand and apply to my work

Thanks :)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1. Please use [code]code here...[/code] tags when posting code.
2. Never use sticky services. They don't do anything useful in new versions of Android.
3. Watch the B4A life cycle tutorial: https://www.b4x.com/etp.html

4. You need to move the code to the starter service and call Service.StartForeground to prevent the OS from killing the service.
 
Upvote 0

Giusy

Active Member
Licensed User
Hi @Erel
Unfortunately I can not solve the problem surely because of my current ignorance in b4a.
I was suggested this program (which I attach) but inserted in my program does not work. Did I miss something and the program is correct?
Thanks if you want to help me
 

Attachments

  • MP.zip
    354.7 KB · Views: 173
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
you not add the Event Sub for this
B4X:
mMediaPlayer.Initialize2("MediaPlayer")
but i guess its because of example project.

if the activity is in pause i think you not get this event so it should be part of starter service.

you should add some Log("...") to follow the app flow.
Initialize2 (EventName As String)
Similar to Initialize2. Complete event will be raised when play back completes.
EventName - The Sub that will handle the Complete event.
 
Last edited:
Upvote 0
Top