Wait for music is finishing to play - got stuck

basil99

Active Member
Licensed User
Longtime User
Wait for music is finishing to play - SOLVED

Hi !

My purpose atm is to load "intro picture", "intro music" and "menu" assests, then wait for "intro music" to stop playing and go to the next step - menu dialog. I do it this way ( gamestage variable is global and contains information on where we are ) with Gameview and MediaPlayer for audio:

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
'Init timer
GameTimer.Initialize( "GameTimer", 30)

' Load and play intro music
IntroMusic.Initialize
IntroMusic.Load(File.DirAssets, "intro.ogg")
IntroMusic.SetVolume(0.5,0.5)
IntroMusic.Play

' Load Intro screen
IntroPicture.Bitmap = LoadBitmap(File.DirAssets, "company-logo.jpg")
IntroPicture.DestRect.Initialize( 0%x, 0%y, 100%x, 100%y )

' Init Game view and display Company logo picture
gv.Initialize("gv")
Activity.AddView(gv, 0, 0, 100%x, 100%y)
gv.BitmapsData.Add( IntroPicture )

' Load menu music
MenuMusic.Initialize
MenuMusic.Load(File.DirAssets, "menu.ogg")
MenuMusic.SetVolume( 1.0, 1.0 )

' Load Menu pictures
MenuPicture.Bitmap = LoadBitmap(File.DirAssets, "menu.jpg")
MenuPicture.DestRect.Initialize( 0%x, 0%y, 100%x, 100%y )

gamestage = 1

End If

' game Logic, depending on Gamestage variable

Select gamestage
Case 1

' Wait until music is stop
If IntroMusic.IsPlaying = 0 Then

gamestage = 2

'Show Menu
IntroMusic.Stop
MenuMusic.Play
gv.BitmapsData.Add( MenuPicture )
gv.Invalidate

End If

Case 2
' Menu stuff here

End Select

End Sub

Programm installs Ok on to the device, but i got this message:

Programm paused on line: line number
If IntroMusic.IsPlaying = 0 Then

This message is always on screen ever when "intro music" is stop
So, what i'm doing wrong ? Or may be all is wrong here ?

Thank you
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Hi !

My purpose atm is to load "intro picture", "intro music" and "menu" assests, then wait for "intro music" to stop playing and go to the next step - menu dialog. I do it this way ( gamestage variable is global and contains information on where we are ) with Gameview and MediaPlayer for audio:

There's something wrong here indeed. B4A is an event-driven language, so you have to use events. And the event to use is Complete.
When you initialize your MediaPlayer, use Initialize2 to define an event prefix (e.g. "MP"). Then add your continuation code in Sub MP_Complete.
 
Upvote 0

basil99

Active Member
Licensed User
Longtime User
There's something wrong here indeed. B4A is an event-driven language, so you have to use events. And the event to use is Complete.
When you initialize your MediaPlayer, use Initialize2 to define an event prefix (e.g. "MP"). Then add your continuation code in Sub MP_Complete.

Thank you, Infomatix, seems now I understand howto do it, and seems it works now
 
Last edited:
Upvote 0
Top