Shoutbox

Q about PlaySound() - 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: Q about PlaySound() (/showthread.php?tid=94564)

Q about PlaySound() by hakxx on 05-11-2010 at 02:52 PM

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


RE: Q about PlaySound() by matty on 05-11-2010 at 02:57 PM

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.


RE: Q about PlaySound() by hakxx on 05-11-2010 at 03:51 PM

Is there another way to play audio from website, or idea ..?

Thank you very much matty..


RE: Q about PlaySound() by matty on 05-11-2010 at 04:40 PM

You can download the file and then play it locally from the computer like I said earlier...


RE: Q about PlaySound() by hakxx on 05-11-2010 at 04:45 PM

will , Thank you matty : )


I'm sorry

I'm try but no result..

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


RE: Q about PlaySound() by matty on 05-11-2010 at 05:27 PM

This code is from the scripting documentation...

Javascript 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);
        }
}


RE: Q about PlaySound() by hakxx on 05-11-2010 at 11:58 PM

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  :$

RE: Q about PlaySound() by Matti on 05-12-2010 at 11:29 AM

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:
    Javascript 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);
        }
    }


RE: Q about PlaySound() by matty on 05-12-2010 at 01:44 PM

You are missing the escape character in this line:

ScriptMenu    +=     "<MenuEntry Id=\"s1">sound1</MenuEntry>";


RE: Q about PlaySound() by hakxx on 05-13-2010 at 06:07 PM

Sorry for the delay, I'll try the code, thank you for you (matti,matty)