Jibble

There is a new version of the forums ready for testing. Please post here if you're willing to help test! We could also use the help of coders!

Author Topic: Music player for Android  (Read 298 times)

cat

  • Mittens Baronet
  • Global Moderator
  • AGS Baker
    • Lifetime Achievement Award Winner
    • cat worked on one or more games that won an AGS Award!
    •  
    • cat worked on one or more games that was nominated for an AGS Award!
Music player for Android
« on: 25 May 2022, 08:20 »
Hi!

I hope this is the right place to post this.

Background: My kids have this Hörbert audio player (https://www.hoerbert.com/wp-content/uploads/sites/5/2017/07/hoerbert-standart-2-e1505730962378.jpg) which basically is a wooden box with a speaker and buttons. Inside is an SD card where you can copy audio files in a certain file structure which results in a playlist for each of the buttons. Since the device is quite heavy, I thought it would be nice to have this on my phone instead for travelling.
I'm using the latest stable AGS (3.5.1. I think it is?) and the Android player on my phone (no idea which version, I can't figure that out). I could update to 3.6.0 if this helps.
I got the basic handling (with lots of swearing about AGS's limited array functionality) but a few questions arise.

1) When I turn off the screen of my phone to save battery, the music stops as well. Is it possible to have this continue running?

2) I included all audio files in the game which makes quite a big vox file and is somewhat impractical because I have to recompile the whole game to change the playlists. Is it possible to a) access audio files from the file system and b) play such files in AGS?

3) When you hold down the back button, a menu will appear. Is it possible to disable this menu? My kids will certainly open this by accident and then cause mayhem on my phone.

Re: Music player for Android
« Reply #1 on: 25 May 2022, 11:27 »
2) I included all audio files in the game which makes quite a big vox file and is somewhat impractical because I have to recompile the whole game to change the playlists. Is it possible to a) access audio files from the file system and b) play such files in AGS?

There's a deprecated PlayMP3File function that may be turned on by disabling "Enforcing new-style audio scripting". The problem with it will be that it returns a result rather than audio channel pointer, but if you have reserved limited number of music channels, then you may deduce its index and access as System.AudioChannels[n].

Also, AGS naturally supports loading any game resources from the filesystem, if they are present there. It's bit complicated with new audio clips system, because the files have to be called how they are called in AudioCache, using generated names instead of original names. That will also only work if you want to provide replacement for registered resources, otherwise there will be no way to run these.

3) When you hold down the back button, a menu will appear. Is it possible to disable this menu? My kids will certainly open this by accident and then cause mayhem on my phone.

No, but if you build for Android in 3.6.0 Editor, it will create an individual APK which does not have this menu. Thinking about it, I don't know if reading files from the file system will work with that form of compiled game; but maybe worth checking out.

Alternatively, this may be a feature request for the universal game player in 3.6.0, perhaps it could have a config setting for disabling this menu.

1) When I turn off the screen of my phone to save battery, the music stops as well. Is it possible to have this continue running?

I'd first try enabling multitasking mode in the game (SetMultitaskingMode), e.g. on desktop systems that keeps game running when they are switched out from. But if that won't work, that's a question of how port works in general.
« Last Edit: 25 May 2022, 11:29 by Crimson Wizard »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: Music player for Android
« Reply #2 on: 25 May 2022, 16:14 »
An idea on how 2) might work:

Generate a txt file with the name of your music files, one per line. Then read from AGS the file and grab the name of each file, and pass it as the filename to read and play the correct file (using the PlayMP3File as suggested by CW).

Of course you'll need to generate this file every time you add a new song to the folder, but it should work (in theory anyway).  (nod)
There are those who believe that life here began out there...

cat

  • Mittens Baronet
  • Global Moderator
  • AGS Baker
    • Lifetime Achievement Award Winner
    • cat worked on one or more games that won an AGS Award!
    •  
    • cat worked on one or more games that was nominated for an AGS Award!
Re: Music player for Android
« Reply #3 on: 25 May 2022, 21:31 »
Ok, I will skip loading the files from storage now. And I'll finally have a look at building a native apk...
I created an Excel sheet for generating the code for setting up the playlists, so it is not that much work (i.e. list7[0] = a7_0;)

SetMultitaskingMode did not work. Even the documentation say nothing about Android:

Quote
Cross-Platform Support

Windows: Yes
Linux: Yes
MacOS: Yes


« Last Edit: 25 May 2022, 21:47 by cat »

eri0o

Re: Music player for Android
« Reply #4 on: 25 May 2022, 22:31 »
I don't think currently SDL2 Android supports keeping the screen off and still keep things executing. I need to research more on the subject before saying more.

Re: Music player for Android
« Reply #5 on: 26 May 2022, 00:21 »
I'm pretty sure you need to write a so-called service for that (i.e. the optional part of an app that runs in the background and keeps running when you leave the app, which is what happens when you turn off the screen).

Learning how to write a simple Music player app that reads folders from the SD card probably takes less time than getting it to work with AGS (if that's even possible).

cat

  • Mittens Baronet
  • Global Moderator
  • AGS Baker
    • Lifetime Achievement Award Winner
    • cat worked on one or more games that won an AGS Award!
    •  
    • cat worked on one or more games that was nominated for an AGS Award!
Re: Music player for Android
« Reply #6 on: 26 May 2022, 08:16 »
Learning how to write a simple Music player app that reads folders from the SD card probably takes less time than getting it to work with AGS (if that's even possible).
You are right, I should finally start getting into writing Android apps. Time to learn something new!

But anyway, except for a few minor issues I managed to get my music player working. Even if there are better tools to achieve my goal, I think it is pretty amazing what you can do with a software that was built for making adventure games  ;-D

Thanks for the answers!