What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Q about PlaySound()

Q about PlaySound()
Author: Message:
hakxx
New Member
*


Posts: 5
37 / Male / Flag
Joined: May 2010
O.P. Roll Eyes  Q about PlaySound()
Hello,

How can use playsound() with a link from a website ??

I know this :

MsgPlus.PlaySound("\c:\\sound.mp3") ;

but how :

MsgPlus.PlaySound("http://shoutbox.menthix.net/sound.mp3") ;

Thanks

This post was edited on 05-11-2010 at 02:52 PM by hakxx.
05-11-2010 02:52 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Q about PlaySound()
You cannot. MsgPlus.PlaySound will only play files locally from your machine. You will need to download and save the file from the webserver and play it.

This post was edited on 05-26-2010 at 01:28 PM by matty.
05-11-2010 02:57 PM
Profile E-Mail PM Find Quote Report
hakxx
New Member
*


Posts: 5
37 / Male / Flag
Joined: May 2010
O.P. RE: Q about PlaySound()
Is there another way to play audio from website, or idea ..?

Thank you very much matty..
05-11-2010 03:51 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Q about PlaySound()
You can download the file and then play it locally from the computer like I said earlier...
05-11-2010 04:40 PM
Profile E-Mail PM Find Quote Report
hakxx
New Member
*


Posts: 5
37 / Male / Flag
Joined: May 2010
O.P. RE: Q about PlaySound()
will , Thank you matty : )
I'm sorry

I'm try but no result..

how to select place download file and play it ..?

05-11-2010 04:45 PM
Profile E-Mail PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Q about PlaySound()
This code is from the scripting documentation...

js code:
function DownloadUpdateFile(sFile)
{
        var Started = MsgPlus.DownloadFile(sFile);
        if(Started)
                Debug.Trace("Downloading file, waiting for event");
        else     
                Debug.Trace("Couldn't start the download");
}

function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
        Debug.Trace("DownloadFileComplete event received for " + Url);
        Debug.Trace("   Success: " + Success);
        if(Success)
        {
                MsgPlus.PlaySound(OutFile);
        }
}
05-11-2010 05:27 PM
Profile E-Mail PM Find Quote Report
hakxx
New Member
*


Posts: 5
37 / Male / Flag
Joined: May 2010
O.P. RE: Q about PlaySound()
code:
function OnGetScriptMenu(Location)
{
    var ScriptMenu = "<ScriptMenu>";
    ScriptMenu    +=     "<MenuEntry Id=\"s1">sound1</MenuEntry>";

    ScriptMenu    += "</ScriptMenu>";
   
    return ScriptMenu;
}


function OnEvent_MenuClicked(sMenuId, nLocation, iOriginWnd) {
if (sMenuId=="s1"){
DownloadUpdateFile("http://ex.com/001.mp3");
}
}


function DownloadUpdateFile(sFile)
{
        var Started = MsgPlus.DownloadFile(sFile);
        if(Started)
                Debug.Trace("Downloading file, waiting for event");
        else     
                Debug.Trace("Couldn't start the download");
}


function OnEvent_DownloadFileComplete(Url, OutFile, Success)
{
        Debug.Trace("DownloadFileComplete event received for " + Url);
        Debug.Trace("   Success: " + Success);
        if(Success)
        {
                MsgPlus.PlaySound(OutFile);
        }
}


^^ it this code true ?

Thank you very very much  :$

This post was edited on 05-12-2010 at 12:00 AM by hakxx.
05-11-2010 11:58 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Q about PlaySound()
That'll probably work (look okay, haven't tested though). However, there are some things you should consider:
  • With that code, you're going to download the .mp3 file every time you click the menu item. I don't know what the purpose of your script is, but wouldn't it be better to download it only the first time to a known location and just play the local file every time it's called afterwards?
  • More importantly: your script is responsible for the clean-up of the downloaded files. That means, if you download a file to a temporary location, Plus! won't delete it when the script terminates. When you don't clean up your temporary files, you'll end up with a big mess of files in your Temp directory.
    Therefore, it would be better if you keep track of all downloaded files and schedule them for deletion on script termination:
    js code:
    // Global array to store downloaded files in
    var arrDownloaded = [];

    // On exit, loop through the array and remove all downloaded files
    function OnEvent_Uninitialize() {
        var FSO = new ActiveXObject("Scripting.FileSystemObject");
        var i = arrDownloaded.length;
        while(i--) {
            try { FSO.GetFile(arrDownloaded[i]).Delete(); } catch(e) { }
        }
        arrDownloaded = [];
    }

    // On download complete, add the file to the downloaded files array
    function OnEvent_DownloadFileComplete(Url, OutFile, Success) {
        Debug.Trace("DownloadFileComplete event received for " + Url);
        Debug.Trace("   Success: " + Success);
        if(Success) {
    >>>        arrDownloaded.push(OutFile);<<<
            MsgPlus.PlaySound(OutFile);
        }
    }
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-12-2010 11:29 AM
Profile E-Mail PM Web Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: Q about PlaySound()
You are missing the escape character in this line:

ScriptMenu    +=     "<MenuEntry Id=\"s1">sound1</MenuEntry>";
05-12-2010 01:44 PM
Profile E-Mail PM Find Quote Report
hakxx
New Member
*


Posts: 5
37 / Male / Flag
Joined: May 2010
O.P. RE: Q about PlaySound()
Sorry for the delay, I'll try the code, thank you for you (matti,matty)
05-13-2010 06:07 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On