Loading sound or photos in Android

Jimmy

Active member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
571
Lots if people wanted to load media on Android. Here's a simple example how to do it one way.
Just change the file to something that you have in your camera gallery!

KitKat changed a few things on the Android platform so the proper way is more complex than this but this works on my test.
1) Go to Settings/Apps/Cerberus Game
2) There you click Permissions (storage on)
3) The next time you run it will work.

Screenshot 2020-11-29 at 11.40.27.png


Code:
' All files
' --------
' /storage/emulated/0/ (main directory)
' Folders here is e.g. Download, Playlists, Pictures etc
' Images = /storage/emulated/0/DCIM/Camera
' Videos = /storage/emulated/0/DCIM/Camera
' Music = /storage/emulated/0/Music
' Documents = /storage/emulated/0/Documents
' Default cerberus-x =  /storage/emulated/0/Android/data/com.cerberus.cerberusgame
' SD memory card = /storage/extSdCard (if card is formatted as NOT shared on Android 4.4+)

Strict
Import mojo2
Import brl.filepath

Function Main:Int()
New myGame
Return 0
End

Class myGame Extends App

Field canvas:Canvas
Field bg:Image
Field timer:Int

Method OnCreate:Int()
SetUpdateRate 0
canvas = New Canvas
timer = 0
Return 0
End

Method OnUpdate:Int()

      If timer = 0
         timer = 1 ' load just one time please
         Local file2 := "cerberus://external/DCIM/Camera/happyfirstadvent.jpg"
         bg = Image.Load(file2)
Endif

Return 0
End

Method OnRender:Int()
canvas.Clear
canvas.DrawImage bg,0,0
canvas.Flush
Return 0
End

End
 
Last edited by a moderator:
Top Bottom