[AddOn] API PlayMusic() & StopMusic()

[AddOn] API PlayMusic() & StopMusic()

by rdrmdr » Sun May 29, 2016 4:54 pm

I'm trying to create an addon that plays a list of musics on the background of the game but if I do:
Code: Select all
PlayMusic("path1")
PlayMusic("path2")
it only plays the 2nd music, ignoring the 1st one.

The music also loops when it gets to the end and I haven't find a way (a event) to know when the music ends or anything at all...

I tried to use:
Code: Select all
StopMusic()
but the problem is I don't know how to use it in the end of it and I'm trying to make it automatically, without any button or click events, just, you enter the game and the playlist plays on the background.

So, is there any way to correctly use the StopMusic() to change from one music to the next one or maybe use PlayMusic() on top. A hard way to do it (that I'm not sure if it's possible) if there's no solution, is to make a timer and after x seconds, change the music. There's no events to this working on Vanilla!
rdrmdr
Grunt
Grunt
 

Re: [AddOn] API PlayMusic() & StopMusic()

by Roadbl0ck » Sun May 29, 2016 7:30 pm

There is no way to do what you want without an external program to parse MP3 files and generate a .lua that can be loaded containing meta-info including song length.

Then your in-game addon would have to manage its own playlist using that information.

That is the way similar addons were using in vanilla (example: WankooMP3)

Later versions of the game introduced PlaySoundKitID which returned a handle to the playing sound for use with StopSound(handleId).
Problem is that also wasn't much use to addons as it couldn't take external files and play by filepath, only the internal ID of built-in client soundfiles was usable.
But it made it easier to shuffle in-game music around (eg. play the zone-A ambience while in zone-B etc)

TL;DR
What you are observing is the expected behavior.
You can only parse your files externally, generate a .lua playlist file with all the information and read that with your addon for timings and such.
Unfortunately my original forum account was locked out.
You can find my previous posts here.
User avatar
Roadbl0ck
Sergeant
Sergeant
 

Re: [AddOn] API PlayMusic() & StopMusic()

by rdrmdr » Sun May 29, 2016 8:04 pm

Thanks for the reply, I tried out the addon but I couldn't find WMP3PlayGen.exe so I tried to do it manually.
What I did was duplicate 2 songs named 1.mp3 and 2.mp3, to the MP3 folder.
My original path is: C:\World of Warcraft Classic\Interface\AddOns\WankooMP3
I tried to add a lua file (WankooMP3Playlist.lua) with the code:
Code: Select all
PlayList = {
    MP3File("Interface\\AddOns\\WankooMP3\\MP3\\1.mp3", 213, "1A", "1B", "1C"),
    MP3File("Interface\\AddOns\\WankooMP3\\MP3\\2.mp3", 209, "2A", "2B", "2C")
}
The test names 1A to 2C show in-game but, for some reason, the music doesn't play. I do listen the game's music. The time works and it shows the label with the 1A 1B 1C text. It also shows information on the chat.

I don't know why it doesn't work but I can see that that addon was exactly what I wanted. It's pretty hard to find such thing. I couldn't find any music related addon and having to work for Vanilla doesn't help too.
rdrmdr
Grunt
Grunt
 

Re: [AddOn] API PlayMusic() & StopMusic()

by Roadbl0ck » Sun May 29, 2016 11:12 pm

There's a couple things you can try.
First of all test your actual .mp3 files to make sure wow sound engine can play them.

Put them in the folder before starting the client (wow can't read new files after it boots up)
Then test from command-line in-game like so:
Code: Select all
/script PlayMusic("Interface\\AddOns\\WankooMP3\\MP3\\1.mp3")

If you hear the soundfile playing so far so good.

Now looking at the code I'm guessing the playlist format is not as you have constructed it.
Try with something like this.
WankooMP3PlayList.lua in the addon folder like you said and put something like this inside
Code: Select all
PlayList = {
  MP3File("1.mp3", 213, "Artist1", "Album1", "SongName1"),
  MP3File("2.mp3", 209, "Artist1", "Album1", "SongName2")
}

Only difference is in the first argument you put the filename after the MP3 addon subfolder.
If you had inside MP3, some genre or Album or whatever subfolders you'd put that path fragment.
Eg. actual full path: <wow install>\Interface\AddOns\WankooMP3\MP3\Dubstep\Trolley Snatcha - The Future.mp3.
Name variable in PlayList would be:
"Dubstep\\Trolley Snatcha - The Future.mp3"
Unfortunately my original forum account was locked out.
You can find my previous posts here.
User avatar
Roadbl0ck
Sergeant
Sergeant
 

Re: [AddOn] API PlayMusic() & StopMusic()

by rdrmdr » Mon May 30, 2016 4:55 pm

Thank you so much, it worked! :D
rdrmdr
Grunt
Grunt
 


Return to Addons & macros