B4J Question GameViewHelper. PlayAudioClip (Mp3File, x) lacks StopPlay or/and End during playback

johnerikson

Active Member
Licensed User
Longtime User
I use GameViewHelper.PlayaudioClip to play background music to pictures.
Does anybody know if/how playback can be stopped before it runs out?
 

johnerikson

Active Member
Licensed User
Longtime User
Thanks!
Have tried with MediaPlayer. It's just that I don't get MediaPlayer to work at all.
Unable to initialize Mediplayer. These are some unsuccessful attempts

B4X:
Private MP As MediaPlayer
‘……………..
    'sDirData = File.DirData("")' = C:\Users\JohnErik\AppData\Roaming   'moved the file .mp3 here
    'MP.Initialize("Complete",  File.GetUri( File.DirData (""),  "Stardust.mp3"))
    'MP.Initialize("Complete",  File.GetUri( sDirData ,  "Stardust.mp3"))
    ' Result:java.lang.IllegalStateException: Toolkit not initialized for both
    
    'sGetUri = File.GetUri( "", "Stardust.mp3") '= file:/D:/Program/B4J/Server/ABMServer/EasyMedia/Objects/Stardust.mp3
    'MP.Initialize("Complete",   sGetUri)  'moved the file .mp3 ubder objects
    'Result: java.lang.IllegalStateException: Toolkit not initialized
    
    'sGetUri = "File:/D:/Program/B4J/Server/ABMServer/EasyMedia/Objects/www/easymedia/EasyVideos/Audio" & PG_UserID & "/Stardust.mp3"
    'MP.Initialize("Complete", sGetUri)
    'Result: java.lang.IllegalStateException: Toolkit not initialized
    
    'MP.Initialize("Complete", File.geturi(File.DirAssets, "Stardust.mp3"))
    'Result: java.lang.IllegalStateException: Toolkit not initialized

The same errors on all options. Maybe something very simple goes wrong!
I have been looking for examples in the forum, but it has not helped me!
However, GameViewHelper is super Simple but missing the stop/end!

I am very grateful for a completely example, I work now with a non-io Project [ABMaterial].
 
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Thanks for the information!

I suspected it, I am not able to safely determine if the examples in the forum are UI or non-UI!, so back to PlayaudioClip if there are no other options. I am allowed to prepare the length of the MP3 files.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
jFX library isn't meant to be used in non-ui applications. MediaPlayer is part of jFX library.

Download the attached library and copy it to the internal libraries folder (v1.03).
It includes an untested StopAudioClip method.
 

Attachments

  • jGameViewHelper.zip
    5.7 KB · Views: 284
Upvote 0

johnerikson

Active Member
Licensed User
Longtime User
Many thanks!

Erel, you are a star, exactly what I needed!
I understand you fix it now, you couldn't have done it faster and better!
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Upvote 0
Top