Shoutbox

Music!Help please! - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Music!Help please! (/showthread.php?tid=80365)

Music!Help please! by Light86 on 12-23-2007 at 06:52 PM

Hello I know how to make appear a window when contact logs in to msn,sayng "welcome" with an image but I wonder if I could make a short music play when this event occours.
Is this possible?And how?
Thank you!:D


RE: Music!Help please! by Matti on 12-24-2007 at 11:13 AM

Yes, you can play a sound! :D

The following code is actually written by fatfreechicken, in his awesome Portal credits easter egg of SessionSaver, but it can be used to play almost any music file. All credits for this code go to him! ;)

  1. First, you'll need to get the short path of your music file. This can be done with the following code and should be executed at script start-up or when the window is created. Don't forget to define the sMusicPath variable globally! ;)
    code:
    var sLongPath = MsgPlus.ScriptFilesPath+"\\MerryXmas.mp3"; //The long path to the file. It's recommended that you put the music file in your script directory if you want to distribute your script later on.
    var lpszShortPath = Interop.Allocate((255+1)*2); //A buffer for the short path.
    Interop.Call("kernel32", "GetShortPathNameW", sLongPath, lpszShortPath, 255); //Call the GetShortPathName function to store the short path in our buffer.
    sMusicPath = lpszShortPath.ReadString(0); //Get the contents of the buffer. This is the variable containing the short path which we can use to play the sound.
  2. Next, you need to play the sound. This can be done right after you executed the code above, but you can also do this when the user clicks a button. Anyway, it's up to you to decide where to place the code:
    code:
    Interop.Call("winmm.dll", "mciSendStringW", "play "+sMusicPath, 0, "", 0); //Start playing the sound.
  3. Eventually, you want to stop the sound a bit earlier, or make sure it's stopped when the window is closed. This is done by simply replacing the "play" command with "stop":
    code:
    Interop.Call("winmm.dll", "mciSendStringW", "stop "+sMusicPath, 0, "", 0); //Stop the sound from playing.
And there you have it! ;)
RE: Music!Help please! by vikke on 12-24-2007 at 11:43 AM

Is there a reason not to use MsgPlus.PlaySound()?

You just call it like this:

code:
MsgPlus.PlaySound(PATH);
It supports:
quote:
Microsoft WAV, Sphere Nist (*.wav)
MPEG Audio (*.mp1;*.mp2;*.mp3)
Amiga (*.iff;*.svx)
Apple/SGI (*.aif)
Berkeley/Ircam (*.sf)
Creative Labs (*.voc)
Ensoniq Paris (*.paf)
GNU Octave (*.mat4;*.mat5)
Sound Forge (*.w64)
Sun/Next (*.au;*.snd)
Free Lossless Audio Codec (*.fla;*.flac)
Apple CAF (*.caf)


RE: RE: Music!Help please! by davidpolitis on 12-24-2007 at 12:03 PM

quote:
Originally posted by vikke
Is there a reason not to use MsgPlus.PlaySound()?
MsgPlus.PlaySound() can be really, really laggy when using an actual song for example. Not too sure about fatfreechicken's way. :P
RE: Music!Help please! by Matti on 12-24-2007 at 12:34 PM

quote:
Originally posted by vikke
Is there a reason not to use MsgPlus.PlaySound()?
Yes! There's no MsgPlus.StopSound(). :P
RE: RE: Music!Help please! by davidpolitis on 12-24-2007 at 12:38 PM

quote:
Originally posted by Mattike
There's no MsgPlus.StopSound(). :P
quote:
The MsgPlus::PlaySound function plays a sound asynchronously. It can also be used to stop the current sound from playing.
quote:
If a sound that was started by this function is already playing, it is stopped before the new sound starts playing.
Get it to play a non-existent sound?
RE: Music!Help please! by Matti on 12-24-2007 at 03:02 PM

Okay, I get your point. Choose whichever method you want. :P


RE: RE: Music!Help please! by pollolibredegrasa on 12-24-2007 at 04:57 PM

quote:
Originally posted by Mattike
Okay, I get your point. Choose whichever method you want. :P
I'll just throw my input in here :P

I'd recommend using MsgPlus.PlaySound() to handle sounds. The only reason I used the code above was because MsgPlus.PlaySound() doesn't support .midi files.