MP mediaplayer low load or memory full?

fifiddu70

Well-Known Member
Licensed User
Longtime User
I do feel a wav audio file, I'm using mediaplayer, but just try to scoltare several times and fast audio file sound of audio files is no more listenable, I must close and restart the application to make it work, why? It seems that pressing multiple times, the buffer will fill and goes haywire the mediaplayer. I am attaching the sample code.

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   
   Dim MP As MediaPlayer
   Dim btnDimmi As Button
   
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("play")
   
end sub
   
Sub btnDimmi_Click
   MP.Initialize 
   MP.Load(File.DirAssets,"fire.wav")
   MP.Play
End Sub
 

stevel05

Expert
Licensed User
Longtime User
You only need to initialize and load the file once if you are going to play the same file. You can do that outside of the play subroutine.

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Dim MP As MediaPlayer
    Dim btnDimmi As Button
    
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("play")
    MP.Initialize 
    MP.Load(File.DirAssets,"fire.wav")
end sub
    
Sub btnDimmi_Click
    MP.Play
End Sub

or if you want to load different files, you should use MP.Release

B4X:
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    
    Dim MP As MediaPlayer
    Dim btnDimmi As Button
    
    
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("play")
    
end sub
    
Sub btnDimmi_Click
    'Check to see if playing has finished, or you could stop it if you want to interrupt the current tune
    If MP.Isplaying then Return
    'If you want to stop it use MP.Stop instead of Return
    If MP.IsInitialized then MP.Release

    MP.Initialize 
    MP.Load(File.DirAssets,"fire.wav")' and change the file name
    MP.Play
End Sub
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
thanks stevel, my error: mp.initialize in button,
now mp.initialize is activity.create firsttime :)
good ok
 
Upvote 0
Top