Playing audiofiles from the computer

Started by Baguettator, Wed 25/11/2020 20:35:59

Previous topic - Next topic

Baguettator

Hi everyone !

Is it possible to allow the player to choose which musics he wants to be played in game ? Like he could put his files somewhere and the game choose one of them to play at a moment.

I read something about the File commande or CDAudio command, but it doesn't seem to work with that. (at least the CDAudio could work, but it is too limited for users that don't have any CD player)

Crimson Wizard

There was this deprecated command PlayMP3File(filename) which you may get to work again if you turn "Enforce new-style audio scripting" off in general settings.
I think this command was intended to play a music file from the game folder.

Something I wonder still is, if you are letting them play their own music, why doing this in game, when user may just play it in their way (with an audio player program)?

Cassiebsg

I've used PlayMP3File before and works fine.  (nod)
There are those who believe that life here began out there...

Baguettator

Crimson : it is always easier and more "immersive" to configure that in-game :)

So I will try that command. But another question : is it possible to "scan" audio files in the game folder and to put them in a listbox ? Like the player could choose which music to play with the list ?


Baguettator

Interesting, thanks Khris !

It is the second time I see things like "$SAVEGAMEDIR$" to indicate location directory.

Is it possible to indicate other directories than "$SAVEGAMEDIR$", "$INSTALLDIR$" or "$APPDATADIR$" ?

Khris

Yes, absolutely, as long as it's inside the game folder.

Here's an actual line I've used:
Code: ags
    lbMapfiles.FillDirList("tilemaps/*.tlc");

Crimson Wizard

#7
Quote from: Baguettator on Thu 26/11/2020 11:28:02
Is it possible to indicate other directories than "$SAVEGAMEDIR$", "$INSTALLDIR$" or "$APPDATADIR$" ?

These tags are for special directories that are set by engine and/or user config, and supposed to work everywhere.

For reading files you may use actual relative or absolute real paths too, you can also let user type it in the Text Box. But I don't know if that would work for PlayMP3File function (never tried). Old functions are sometimes inconsistent in what they do...

Just be sure to not put absolute paths yourself in the script (other than for testing), because these are system-dependent and may not exist on other computers.

Baguettator

#8
Thanks I understand now !

To test it, which folderthe editor uses as the "game folder" ? I mean : before I compile the game. If I want to use something similar as Khris's code :

Code: ags
Listmusics.FillDirList("musics/*.mp3");


Where should I create the "music" folder to be able to test it before compiling ?

EDIT : Oh, and sorry, I found that I could do another thing, but I need help for that :

Is it possible to create a PlayList with the MP3 audio files used with the function PlayMP3File ? I managed to do something with a Listbox (and randomly choose the index's string), but I don't know how to choose another clip when the first one has finished.

EDIT 2 : I found a "playlist module" on this forum, but it is old and the download link is dead...

Monsieur OUXX

#9
Quote from: Baguettator on Sat 28/11/2020 17:56:16
To test it, which folder the editor uses as the "game folder" ?

Whatever folder the game is running from. So if you're running it from the Editor, then from memory it's the Compiled/Windows subfolder or something like that. (because yes, the game does need to be compiled to run, even when debugging from the Editor  ;) ) If you're not sure (I never am!) then just put a dummy file in the folder and try to open it in your game until you find the correct folder. For example :
Code: ags

//After putting a file named dummy.txt in the Compiled/Windows/music folder : 
File* f = File.Open("music/dummy.txt");
if (f==null) { AbortGame("Woops! Wrong folder!"); }

I would advise to ALWAYS add $SAVEGAMEDIR$", "$INSTALLDIR$" or "$APPDATADIR$ when opening a file. This avoids a lot of human mistakes, especially if you run your game as administrator and forgot that other users might not do that / might not have access rights to the execution folder.

Extra tip: I myself being a lazy bum put my files manually in the execution folder BUT if I recall there's a fancy method to put files in a special AGS Editor folder so that they get copied to the Compiled folder automatically. Something like "Data"? I'm not sure.


Quote from: Baguettator on Sat 28/11/2020 17:56:16
Is it possible to create a PlayList with the MP3 audio files used with the function PlayMP3File ? I managed to do something with a Listbox (and randomly choose the index's string), but I don't know how to choose another clip when the first one has finished.
There's two questions in one : 1) Is it possible to create a list (i.e. an array) of file names to play from? --> Yes. I don't know if you've put the file names into the list manually but putting them there programmatically shouldn't be too hard 2) How do I detect that the track has ended? That's usually performed using one of two ways : a) calculating if the time elapsed is equal or greater to the track's length. (there should be functions for that?) OR b) check if the audio channel where the track is/was playing is still being used. "b" is the modern way but I think that's not compatible with the old "PlayMP3" function that you're using. So maybe try "a".

 

Baguettator

Hi again !

I managed to do what I needed, but now I encounter the following problem : the function PlayMP3File plays a mp3 file without stopping at the end, so I can't change the music playing...

I have a script that scans the audiochannels playing, and if there are not, I randomly choose a music from the player's playlist. But because the PlayMP3File is playing the file "non-stop", it never changes the music that is playing...

Any idea to solve that ? Is there an old function that could verify that the file isn't playing anymore ?

Crimson Wizard

Quote from: Baguettator on Tue 05/01/2021 16:16:01
I managed to do what I needed, but now I encounter the following problem : the function PlayMP3File plays a mp3 file without stopping at the end, so I can't change the music playing...

I have a script that scans the audiochannels playing, and if there are not, I randomly choose a music from the player's playlist. But because the PlayMP3File is playing the file "non-stop", it never changes the music that is playing...

Any idea to solve that ? Is there an old function that could verify that the file isn't playing anymore ?

IIRC all the old music functions always play music on same channel 2 for compatibility reasons (System.AudioChannels[2]). You could probably test the music position to see when it about to end.

SMF spam blocked by CleanTalk