Q about PlaySound() |
Author: |
Message: |
hakxx
New Member
Posts: 5
37 / /
Joined: May 2010
|
O.P. 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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
hakxx
New Member
Posts: 5
37 / /
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
hakxx
New Member
Posts: 5
37 / /
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 |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
hakxx
New Member
Posts: 5
37 / /
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 |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
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);
}
}
|
|
05-12-2010 11:29 AM |
|
|
matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
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 |
|
|
hakxx
New Member
Posts: 5
37 / /
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 |
|
|
|