Last Comment Bug 104174 - implement nsSound::PlaySystemSound() for linux
: implement nsSound::PlaySystemSound() for linux
Status: VERIFIED DUPLICATE of bug 179138
: helpwanted
Product: SeaMonkey
Classification: Client Software
Component: MailNews: Message Display (show other bugs)
: Trunk
: x86 Linux
: P3 normal with 11 votes (vote)
: Future
Assigned To: (not reading, please use seth@sspitzer.org instead)
: stephend@netscape.com (gone - use stephen.donner@gmail.com instead)
:
Mentors:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2001-10-10 21:22 PDT by (not reading, please use seth@sspitzer.org instead)
Modified: 2004-11-22 17:25 PST (History)
27 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
The OS/2 version (1.19 KB, patch)
2001-12-10 11:58 PST, Mike Kaply [:mkaply]
no flags Details | Diff | Splinter Review
Fix for Os/2 (4.62 KB, patch)
2002-04-01 15:33 PST, Mike Kaply [:mkaply]
jhpedemonte: review+
mozilla: superreview+
asa: approval+
Details | Diff | Splinter Review

Description (not reading, please use seth@sspitzer.org instead) 2001-10-10 21:22:37 PDT
PlaySystemSound works for windows, and with #104140, it will be done on mac.

does linux have a concept of system sounds?  if not, maybe we could do this:

we currently call PlaySystemSound("Mailbeep") (in nsStatusBarBiffManager.cpp) 
to play the new mail sound.

for linux, here is what I was thinking:

NS_IMETHODIMP
nsSound::PlaySystemSound(const char *aSoundAlias)
{
  nsresult rv;
  nsCAutoString prefName("system.sound.");
  prefName += aSoundAlias;

  nsXPIDLCString soundPrefValue;

  rv = pref->CopyCharPref(prefName.get(), getter_Copies(soundPrefValue));
  if (NS_SUCCEEDED(rv) && soundUrl.Length() > 0) {
    // create a nsURI, set the spec with soundPrefValue;
    rv = PlaySound(soundUrl);
  }
  else {
    rv = Beep();
  }
  return rv;
}

then, in unix.js we'd define 

pref("system.sound.Mailbeep","chrome://messenger/content/newmailsound.wav");

if users want to override on linux, they'd set "system.sound.Mailbeep" in their 
prefs.js to be a local file url.

comments?
Comment 1 (not reading, please use seth@sspitzer.org instead) 2001-10-10 21:24:40 PDT
+ rv = PlaySound(soundUrl);

should be

rv = Play(soundUrl);

but you get the idea.
Comment 2 Christopher Blizzard (:blizzard) 2001-10-11 12:14:13 PDT
Well, linux doesn't have an asyncronous way of playing sounds really unless you
count write().  It just writes to a device on the filesystem that may or may not
be writable, may or may not exist, and may or may not be blocked by another program.
Comment 3 (not reading, please use seth@sspitzer.org instead) 2001-10-11 16:31:14 PDT
blizzard, the goal here would be to make it so on new mail we'd do something
other than just beep (on linux).

as far as making Play() async, that's be something else.

or am I misunderstanding your point?
Comment 4 Francisco León 2001-10-12 09:52:19 PDT
Why is the OS marked to win 2000?
Anyway, the main problem here is that linux does not have a "default sound"
So if we are going to make mail beep to the soundcard, we would need to "create"
the beep ourselves.

So i guess what i am trying to say is that we only need a UI for setting the
sound we want to play, since this works already via a pref line, thus the fix
should be trivial
Comment 5 Christopher Blizzard (:blizzard) 2001-10-12 09:55:21 PDT
OK, here's what I suspect that you would have to do.  When you got the request
to play you would pass in a stream ( I haven't looked at the interface ) into a
new thread that would handle the playing so the main thread wouldn't be blocked.
 It would handle opening the device, reading from the moz stream, writing to the
device, closing the device and then the thread could exit.

It sounds reasonable and reasonably simple to implement.  The only catch is
where we put the file.  Does it need to be in a .jar file?  There may be issues
reading from the other thread but I'm not sure - I've never worked with that
part of the code.
Comment 6 (not reading, please use seth@sspitzer.org instead) 2001-10-12 12:26:30 PDT
blizzard, what you describe is the fix for making nsISound::Play() async on linux.

this bug is about mapping PlaySystemSound() to Play(), using an .wav that we
ship with (inside the messenger .jar) since there is no standard way of
specifying system sounds on linux, like there is on mac or windows.
Comment 7 Pierre Phaneuf 2001-10-12 13:53:24 PDT
Oh, yet another thread... You can select() on the /dev/dsp device, BTW, no need
for a thread. If you already have a select() loop somewhere, you can just stick
this in there.

Excuse me if the architecture of the browser is not like that, I only hacked the
bowels of XPCOM.
Comment 8 Christopher Blizzard (:blizzard) 2001-10-12 15:54:43 PDT
Oh, sorry.  I completely missed the point of the bug.  Seth, your solution looks
fine to me.  Like I said, though, we should probably put the sound outside of a
jar file to make it easy to stream right to the device.  res/ is probably the
right place.
Comment 9 Akkana Peck 2001-11-15 18:00:18 PST
Filed bug 110385 on the asynchrony issue.
Comment 10 (not reading, please use seth@sspitzer.org instead) 2001-12-04 16:18:20 PST
update, the system sound is now "_moz_mailbeep"

see
http://lxr.mozilla.org/mozilla/source/mailnews/base/src/nsStatusBarBiffManager.cpp#122

so the pref would be something like

pref("system.sound._moz_mailbeep","res://newmailsound.wav");

Comment 11 (not reading, please use seth@sspitzer.org instead) 2001-12-07 15:21:02 PST
mike and I traded some emails, he might be doing some of this for OS/2
Comment 12 Mike Kaply [:mkaply] 2001-12-10 11:58:10 PST
Created attachment 61127 [details] [diff] [review]
The OS/2 version

Here is the OS/2 version. Linux should look just about the same.

Things are going to be weird on OS/2, though, and I'm looking for some help.

I'd prefer not to write code that plays the audio explictly - I just want to
invoke a sound player with the file that is passed in.

Is there anyway to take a res:// URI and get the physical file location?

Right now I'm using a file:/// URI
Comment 13 Hixie (not reading bugmail) 2002-01-16 14:19:56 PST
KDE and Gnome have system sounds. We should support those (at least the Gnome
one, given that we're doing GTK themes).
Comment 14 Francisco León 2002-01-16 14:31:51 PST
why cant we just send the sound to /dev/dsp instead of figuring out how to pass 
the sound to ArtS and Esd and so forth? Let's make a method that would work on 
any linux system
Comment 15 Daniel Mota Leite 2002-01-17 00:10:18 PST
agree

why not a easy, unix way...
run command after new mail...
people could put there what 
they want, most of then would choose:
play ~/sound/newmail.wav

this way is simple and yet 
powerfull, all it needs is a few code lines and a new pref textarea to write the command 
Comment 16 Michael McDougall 2002-02-25 12:47:04 PST
Please fix this soon. My new Compaq Presario 5320us has not internal speaker so
I have no audio notification at all when I get new mail. Apparently many of the
new Presarios have no internal speaker so this may affect a lot of users.
Comment 17 Mike Kaply [:mkaply] 2002-04-01 15:32:16 PST
OK, I did this for OS/2 and my solution will probably work on all platforms.

I just right out the data as a temporary file and then play it.
Comment 18 Mike Kaply [:mkaply] 2002-04-01 15:33:46 PST
Created attachment 77112 [details] [diff] [review]
Fix for Os/2

This will probably work for other platforms, with just a different mechanism
for playing the file.
Comment 19 jhp (no longer active) 2002-04-02 14:30:20 PST
Comment on attachment 77112 [details] [diff] [review]
Fix for Os/2

r=pedemont if you get rid of the GET_WORD defines
Comment 20 Mike Kaply [:mkaply] 2002-04-02 16:17:47 PST
Comment on attachment 77112 [details] [diff] [review]
Fix for Os/2

sr=blizzard because this is OS/2 only code.

I am also making a change to this code to only work with WAV files by looking
for RIFF like Linux does.
Comment 21 Asa Dotzler [:asa] 2002-04-02 17:18:25 PST
Comment on attachment 77112 [details] [diff] [review]
Fix for Os/2

a=asa (on behalf of drivers) for checkin to the 1.0 trunk
Comment 22 Mike Kaply [:mkaply] 2002-04-03 07:12:24 PST
Os/2 stuff checked in. You guys are on your own for Linux.
Comment 23 Carsten Menke 2002-04-17 05:14:42 PDT
Just wonder why the Calendar already plays Sound on Linux, and the Mail News
couldn't ?
Comment 24 Mike Potter 2002-05-01 07:22:39 PDT
Here's the function to play a sound in Linux calendar:
function playSound( ThisURL )
{
   ThisURL = "chrome://calendar/content/sound.wav";

   var url =
Components.classes["@mozilla.org/network/standard-url;1"].createInstance();
   url = url.QueryInterface(Components.interfaces.nsIURL);
   url.spec = ThisURL;

   var sample = Components.classes["@mozilla.org/sound;1"].createInstance();
   
   sample = sample.QueryInterface(Components.interfaces.nsISound);

   sample.play( url );
}
Comment 25 Al Peak 2002-05-21 08:05:43 PDT
A temporary cure for those of us pineing for a sound other than "BEEP" on Linux:

Download softbeep
(http://www.stud.uni-hamburg.de/users/lennart/projects/softbeep/), which lets
you "wrap" any program's "bell" sound to do something else.  I just run
"softbeep mozilla" and all my beeping woes go away.

Its a hack job, but it'll have to do until PlaySystemSound() does something
other than ::gdk_beep().
Comment 26 Don J. Rude 2002-09-16 09:52:33 PDT
Perhaps with the demise of 64475 we should be depending on bug 64462
Comment 27 David :Bienvenu 2002-12-08 15:49:58 PST
-> front end
Comment 28 Ari Pollak 2003-02-14 13:26:58 PST
Isn't sound already implemented on linux in 1.3b?
Comment 29 David Johnson 2003-02-14 14:13:12 PST
Nope, not implemented :-(

Are people actually working on this?
Comment 30 Dave Sp 2003-03-08 17:17:03 PST
Comment #15 (specifying a command to run) would be the best for Unix/Linux.
Comment 31 Ari Pollak 2003-03-08 17:19:40 PST
Yes, a command could be an option, but using something like libao would be
preferable, which will automatically select the proper sound output mechanism
for the system.
Comment 32 Dave Sp 2003-03-11 17:59:56 PST
I'm not sure what "libao" provides, but seeing as this bug has been open for 17
months, it may be time for someone to provide a "hack" (i.e. a command-line
option) to get this going.

And I'm not saying I'm above being the one to make the hack.  It'll just take me
a little while to make the time to learn the build environment, bug-submission
procedure, etc.
Comment 33 Koike Kazuhiko 2003-05-27 00:05:09 PDT

*** This bug has been marked as a duplicate of 179138 ***
Comment 34 Stephen Donner [:stephend] 2003-09-20 12:54:01 PDT
Verified dup

Note You need to log in before you can comment on or make changes to this bug.