MODULE: Playlist - It's a playlist module! - Updated 6 Feb 2012 (Working Link)

Started by monkey0506, Thu 07/07/2011 07:19:18

Previous topic - Next topic

monkey0506

In response to this totally awesome thread, I decided to make a module to handle music playlists! I'm aware of course that we already have AudioClip.PlayQueued, but that's a pretty basic and limiting function if you want to implement a full music player into your incredible AGS games!

I'm on a tight schedule to get out all of my Release Somethings, so I haven't typed up all of the documentation for this yet, but the call tips should be enough to get you started, and hopefully everything is intuitive enough that documentation isn't really completely necessary.

Download v1.1

For now, I'll explain a few things. First, an example:

Example:

Code: ags
// game_start
Playlist.AddClip(aMusic1); // add our clips to the playlist
Playlist.AddClip(aMusic2);
Playlist.AddClip(aMusic3);
// ..etc.
Playlist.Repeat = eRepeat; // set the playlist to repeat
Playlist.Shuffle = ePlaylistShuffleAll; // set the playlist to shuffle
Playlist.Play(); // starts the playlist playing!

// on_key_press
if (keycode == '[') Playlist.PlayPrevious(); // play the previous track
else if (keycode == ']') Playlist.PlayNext(); // play the next track
else if (keycode == ' ')
{ // spacebar
  if (Playlist.IsPaused) Playlist.UnPause(); // if the playlist was paused, unpause it
  else Playlist.Pause(); // otherwise, pause it
}


Okay, so I'm hoping this is straightforward enough, especially with the comments, so as to clarify what's going on. But I'll try to break it down. Please bear in mind that I plan to release a demo with resplendent GUI to exhibit this module, but since the majority of the codebase is (apparently) stable, I figured why not release it upon the world and let you help me debug? :=

06 February 2012

v1.1 is here! Changes include:

- New enum PlaylistRepeatStyle: eOnce and eRepeat are still valid, but this was needed to add ePlaylistRepeatOne, so that you can now repeatedly loop a single clip.

- Added functions Playlist.Save and Playlist.Load: This allows you to store multiple playlists. Since there is not currently a global array of AudioClips, this list can only be persisted in-game, and across save games. That is, you cannot save a playlist to a file and read it back.

- Added Playlist.PlayFrom, to allow you to play a specific clip in the playlist, by index. This will start the playlist playing if it is not.

- Added Playlist.Resume as a synonym for Playlist.UnPause.

- Added properties Playlist.Volume and Playlist.Mute. Playlist.Volume is a shortcut to Playlist.Channel.Volume, with the exception that it can be persisted even when Playlist.Channel is changed or is null. Playlist.Mute of course just temporarily sets the channel volume to 0, but this does not affect the Playlist.Volume.

- Added stopClipIfPlaying optional parameter to Playlist.Remove to allow you to override the default behaviour, which is to stop the current playing clip and skip to the next if it is the clip being removed from the playlist.

- Fixed Playlist.Clear resetting the Repeat and Shuffle styles.

- Fixed bug if an invalid clip was specified to Playlist.RemoveClip.

- Removed some debugging code that was inadvertently left in v1.0 of the module.

- Included documentation!! Yay! o/

Thanks guys, and hope you like the module!

Download v1.1

P.S. It improves your sex life! No, really! Kick some sexy audio tracks into your game and then hook this playlist functionality in and you sir will go "All night long, all night!" ;D

tzachs

Dude, you're on fire!
Releasing 2.5 useful modules in a couple of days, you make the rest of us look bad...

Anyways, the interface on this one looks very friendly, just one comment:
I think that's "Resume" is more suitable than "UnPause" as I believe that's the standard used.

monkey0506

Yes, very well then. I shall add a synonym function just for you sir. :=

But first, to go get my truck out of the shop and give away all of my monies! Hooray! 8)

FamousAdventurer77

*insert Nathan Explosion esque "Awwwwwweessssssome!" here*

Ooh I can't wait to implement this sucker.
If you want to know the Bible's contents, just watch Lord of the Rings or listen to the last 8 Blind Guardian albums. It's pretty much the same thing.

monkey0506

I'm developing v1.1 as we speak, and see, part of the reason I wanted to make a functional music player as a demo is to better understand what type of features you might want/need out of such a module as this. So, things to look forward to in the upcoming version:

- A new enum to allow for "repeat one" functionality instead of only repeating all or none of the tracks.
- Playlist.Save and Playlist.Load to allow you to store multiple playlists (NOTE: Since AGS doesn't currently have a "generic" way of accessing the audio tracks, the playlists can only be saved per game-session. Save games would be able to store this information, but you can't save it to an external file since there would be no way for the module to read it back.)
- Playlist.Resume! Which just calls Playlist.UnPause! :=
- Playlist.Volume and Playlist.Mute!
- Documentation!!1

If you would like to be able to save playlists to an external file, or use the Playlist module to read external audio files, show your support!

Also, this:



Everything in the lower half is functional except the "Rewind" and "Fast Forward" buttons and the "Seek" slider. Nothing in the upper half is functional yet! :=

Please let me know if there's any other specific features that v1.0 is missing and I'll try to include them in v1.1!



m0ds

Nice job, I may have to replace my in-game jukebox with this. One question though, when can we expect CD audio and an eject cd-tray option? And how about being able to select a folder full of mp3's/oggs from the games folder (a bit like RCT3, where you fill a particular subfolder full of your own mp3s?) I'd love for my players to be able to play their own cd's or music folders in-game :)

Also, is music only capable of being in one track? For instance, could it be possible to have the playlist fadeout (then mute, possible pause too) and then let the game play a set piece of music and once that's finished have the playlist fade in and continue? Wishlist features that's all ;) What you've already done will certainly simplify things a lot.

monkey0506

Interesting suggestion about CD tracks. Presumably...hmm..yes, I could actually make that work I think.

As for loading external audio, AGS 3.2 removes that ability, which this module explicitly depends upon (as it uses the AudioClip and AudioChannel types, amongst other things). If you look a few posts up I linked to a suggestion to implement a dynamic audio type to read audio files from disk as this is a regression against prior AGS versions...didn't get much attention though.

By the way, I don't know what I was drinking when I wrote half of this code, but there's a million rather obvious bugs in even the latest version. It's functional, but if you use the wrong function the wrong way then it explodes violently. I'm working on fixing that. :P

Fortun

Maybe it's not that good idea to revive this dead topic, but... is it possible to get a mirror to this module, or something like that? Only link to module is dead :(

sorry for my bad english (-_-)

Dualnames

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Georgeqgreg

Great, this helps me too. I lost the original in a hard drive crash. I guess that's thanks from both of us! :cheesy:

jamesreg

Does this still work?
Will this allow me to allow a player to create a playlist in game?
Say have a list of songs they can select and as they select them it will add them to a playlist?

Baguettator

Hi there ! I would like to download this module , but the link seems to be dead... Any reason for that ?

SMF spam blocked by CleanTalk