forked from mirrors/gecko-dev
Backing out bug 520417
--HG-- rename : widget/src/beos/nsSystemSoundService.cpp => widget/src/beos/nsSound.cpp rename : widget/src/beos/nsSystemSoundService.h => widget/src/beos/nsSound.h rename : widget/src/cocoa/nsSystemSoundService.h => widget/src/cocoa/nsSound.h rename : widget/src/cocoa/nsSystemSoundService.mm => widget/src/cocoa/nsSound.mm rename : widget/src/gtk2/nsSystemSoundService.cpp => widget/src/gtk2/nsSound.cpp rename : widget/src/gtk2/nsSystemSoundService.h => widget/src/gtk2/nsSound.h rename : widget/src/os2/nsSystemSoundService.cpp => widget/src/os2/nsSound.cpp rename : widget/src/os2/nsSystemSoundService.h => widget/src/os2/nsSound.h rename : widget/src/photon/nsSystemSoundService.cpp => widget/src/photon/nsSound.cpp rename : widget/src/photon/nsSystemSoundService.h => widget/src/photon/nsSound.h rename : widget/src/qt/nsSystemSoundService.cpp => widget/src/qt/nsSound.cpp rename : widget/src/qt/nsSystemSoundService.h => widget/src/qt/nsSound.h rename : widget/src/windows/nsSystemSoundService.cpp => widget/src/windows/nsSound.cpp rename : widget/src/windows/nsSystemSoundService.h => widget/src/windows/nsSound.h
This commit is contained in:
parent
c2b874d630
commit
df751e7973
59 changed files with 1972 additions and 2195 deletions
|
|
@ -110,7 +110,6 @@ XPIDLSRCS = \
|
|||
nsIDragDropHandler.idl \
|
||||
nsIScriptEventHandler.idl \
|
||||
nsIScriptEventManager.idl \
|
||||
nsISoundPlayer.idl \
|
||||
nsIImageLoadingContent.idl \
|
||||
nsIObjectLoadingContent.idl \
|
||||
nsIFrameLoader.idl \
|
||||
|
|
|
|||
|
|
@ -119,11 +119,6 @@
|
|||
#define NS_FRAME_UTIL_CID \
|
||||
{ 0xa6cf90d5, 0x15b3, 0x11d2,{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
|
||||
// {1C3F4572-FF54-4e7f-994C-6F9C8A4B85FF}
|
||||
#define NS_SOUNDPLAYER_CID \
|
||||
{ 0x1c3f4572, 0xff54, 0x4e7f, \
|
||||
{ 0x99, 0x4c, 0x6f, 0x9c, 0x8a, 0x4b, 0x85, 0xff } }
|
||||
|
||||
|
||||
// XXX This should really be factored into a style-specific DLL so
|
||||
// that all the HTML, generic layout, and style stuff isn't munged
|
||||
|
|
|
|||
|
|
@ -1497,10 +1497,6 @@ public:
|
|||
return WrapNative(cx, scope, native, nsnull, vp, aHolder, aAllowWrapping);
|
||||
}
|
||||
|
||||
// Play an event sound of the aEventID. aEventID must be a value that is
|
||||
// declared in nsISystemSoundService.
|
||||
static nsresult PlayEventSound(PRUint32 aEventID);
|
||||
|
||||
private:
|
||||
|
||||
static PRBool InitializeEventTable();
|
||||
|
|
|
|||
|
|
@ -1,68 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURL;
|
||||
|
||||
/**
|
||||
* nsISoundPlayer provides simple sound playback.
|
||||
*
|
||||
* The implementation uses the HTML5 <audio> element, so supports any format
|
||||
* supported by <audio>. Gecko in its default configuration supports Wave (with
|
||||
* 8-bit or 16-bit PCM samples and at most 2 channels), and Ogg Vorbis.
|
||||
*
|
||||
* When you call play() before the previously playing sound is finished,
|
||||
* the previous sound isn't stopped automatically, so the sounds overlap.
|
||||
*
|
||||
* If you don't want the overlap, you should call stop() before play().
|
||||
* The stop() method stops playing all in-progress sounds that are being played
|
||||
* via this interface.
|
||||
*
|
||||
* NOTE: nsISystemSoundService calls stops() method automatically before it
|
||||
* plays a system sound.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(8AAB1533-7B56-4861-9390-094658447A0C)]
|
||||
interface nsISoundPlayer : nsISupports
|
||||
{
|
||||
void play(in nsIURL aURL);
|
||||
void stop();
|
||||
};
|
||||
|
||||
|
|
@ -118,7 +118,6 @@ CPPSRCS = \
|
|||
nsScriptElement.cpp \
|
||||
nsScriptEventManager.cpp \
|
||||
nsScriptLoader.cpp \
|
||||
nsSoundPlayer.cpp \
|
||||
nsStubDocumentObserver.cpp \
|
||||
nsStubImageDecoderObserver.cpp \
|
||||
nsStubMutationObserver.cpp \
|
||||
|
|
|
|||
|
|
@ -167,7 +167,6 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_XTFSERVICE_CID);
|
|||
#include "nsHtml5Module.h"
|
||||
#include "nsPresContext.h"
|
||||
#include "nsLayoutStatics.h"
|
||||
#include "nsISystemSoundService.h"
|
||||
|
||||
#ifdef IBMBIDI
|
||||
#include "nsIBidiKeyboard.h"
|
||||
|
|
@ -5173,16 +5172,3 @@ nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
|
|||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// static
|
||||
nsresult
|
||||
nsContentUtils::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISystemSoundService> sysSound =
|
||||
do_GetService("@mozilla.org/systemsoundservice;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(sysSound, NS_ERROR_FAILURE);
|
||||
return sysSound->PlayEventSound(aEventID);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,183 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSoundPlayer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsIDOMEvent.h"
|
||||
#include "nsIDOMEventTarget.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "nsPrintfCString.h"
|
||||
#endif
|
||||
|
||||
nsSoundPlayer* nsSoundPlayer::sInstance = nsnull;
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSoundPlayer, nsISoundPlayer, nsIDOMEventListener)
|
||||
|
||||
|
||||
nsSoundPlayer::nsSoundPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
nsSoundPlayer::~nsSoundPlayer()
|
||||
{
|
||||
if (this == sInstance) {
|
||||
sInstance = nsnull;
|
||||
}
|
||||
#ifdef MOZ_MEDIA
|
||||
for (PRInt32 i = mAudioElements.Count() - 1; i >= 0; i--) {
|
||||
RemoveEventListeners(mAudioElements[i]);
|
||||
}
|
||||
#endif // MOZ_MEDIA
|
||||
}
|
||||
|
||||
/* static */ nsSoundPlayer*
|
||||
nsSoundPlayer::GetInstance()
|
||||
{
|
||||
if (!sInstance) {
|
||||
sInstance = new nsSoundPlayer();
|
||||
}
|
||||
NS_IF_ADDREF(sInstance);
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
#ifdef MOZ_MEDIA
|
||||
|
||||
void
|
||||
nsSoundPlayer::RemoveEventListeners(nsIDOMHTMLMediaElement *aElement)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(aElement));
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("ended"), this, PR_TRUE);
|
||||
target->RemoveEventListener(NS_LITERAL_STRING("error"), this, PR_TRUE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSoundPlayer::CreateAudioElement(nsIDOMHTMLMediaElement **aElement)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMHTMLMediaElement> audioElement =
|
||||
do_CreateInstance("@mozilla.org/content/element/html;1?name=audio", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(audioElement,
|
||||
"do_CreateInterface succeeded, but the result is null");
|
||||
audioElement->SetAutoplay(PR_TRUE);
|
||||
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(audioElement));
|
||||
target->AddEventListener(NS_LITERAL_STRING("ended"), this, PR_TRUE);
|
||||
target->AddEventListener(NS_LITERAL_STRING("error"), this, PR_TRUE);
|
||||
NS_ADDREF(*aElement = audioElement);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif // MOZ_MEDIA
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoundPlayer::Play(nsIURL* aURL)
|
||||
{
|
||||
#ifdef MOZ_MEDIA
|
||||
nsCAutoString spec;
|
||||
nsresult rv = aURL->GetSpec(spec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (spec.IsEmpty()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLMediaElement> audioElement;
|
||||
rv = CreateAudioElement(getter_AddRefs(audioElement));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mAudioElements.AppendObject(audioElement);
|
||||
|
||||
rv = audioElement->SetAttribute(NS_LITERAL_STRING("src"),
|
||||
NS_ConvertUTF8toUTF16(spec));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
audioElement->Load();
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // MOZ_MEDIA
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoundPlayer::Stop()
|
||||
{
|
||||
#ifdef MOZ_MEDIA
|
||||
for (PRInt32 i = mAudioElements.Count() - 1; i >= 0; i--) {
|
||||
nsCOMPtr<nsIDOMHTMLMediaElement> audioElement = mAudioElements[i];
|
||||
if (!audioElement) {
|
||||
NS_WARNING("mAudioElements has null item");
|
||||
continue;
|
||||
}
|
||||
RemoveEventListeners(audioElement);
|
||||
audioElement->Pause();
|
||||
}
|
||||
mAudioElements.Clear();
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // MOZ_MEDIA
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoundPlayer::HandleEvent(nsIDOMEvent *aEvent)
|
||||
{
|
||||
#ifdef MOZ_MEDIA
|
||||
NS_ENSURE_ARG_POINTER(aEvent);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
rv = aEvent->GetTarget(getter_AddRefs(target));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(target, NS_OK);
|
||||
|
||||
nsCOMPtr<nsIDOMHTMLMediaElement> audioElement = do_QueryInterface(target);
|
||||
NS_ENSURE_TRUE(audioElement, NS_OK);
|
||||
|
||||
RemoveEventListeners(audioElement);
|
||||
|
||||
mAudioElements.RemoveObject(audioElement);
|
||||
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // MOZ_MEDIA
|
||||
}
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSoundPlayer_h__
|
||||
#define __nsSoundPlayer_h__
|
||||
|
||||
#include "nsISoundPlayer.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
|
||||
#ifdef MOZ_MEDIA
|
||||
#include "nsIDOMHTMLMediaElement.h"
|
||||
#include "nsCOMArray.h"
|
||||
#endif // MOZ_MEDIA
|
||||
|
||||
class nsSoundPlayer : public nsISoundPlayer,
|
||||
public nsIDOMEventListener
|
||||
{
|
||||
public:
|
||||
nsSoundPlayer();
|
||||
virtual ~nsSoundPlayer();
|
||||
|
||||
static nsSoundPlayer* GetInstance();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUNDPLAYER
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
|
||||
protected:
|
||||
static nsSoundPlayer* sInstance;
|
||||
|
||||
#ifdef MOZ_MEDIA
|
||||
nsCOMArray<nsIDOMHTMLMediaElement> mAudioElements;
|
||||
|
||||
nsresult CreateAudioElement(nsIDOMHTMLMediaElement **aElement);
|
||||
void RemoveEventListeners(nsIDOMHTMLMediaElement *aElement);
|
||||
#endif // MOZ_MEDIA
|
||||
};
|
||||
|
||||
#endif /* __nsSoundPlayer_h__ */
|
||||
|
|
@ -249,7 +249,6 @@ _TEST_FILES += \
|
|||
test_paused_after_ended.html \
|
||||
test_progress2.html \
|
||||
test_progress4.html \
|
||||
test_sound.xul \
|
||||
test_wav_ended1.html \
|
||||
test_wav_ended2.html \
|
||||
test_wav_onloadedmetadata.html \
|
||||
|
|
|
|||
|
|
@ -1,242 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
||||
type="text/css"?>
|
||||
<window title="sound tests"
|
||||
onload="runTests()"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<title>sound tests</title>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
||||
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<p id="display">
|
||||
</p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
</pre>
|
||||
</body>
|
||||
|
||||
<script class="testbody" type="application/javascript">
|
||||
<![CDATA[
|
||||
|
||||
function runTests()
|
||||
{
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
|
||||
const nsISystemSoundService = Components.interfaces.nsISystemSoundService;
|
||||
var sysSoundService = Components.classes["@mozilla.org/systemsoundservice;1"].
|
||||
getService(nsISystemSoundService);
|
||||
isnot(sysSoundService, null, "failed to get the nsISystemSoundService");
|
||||
|
||||
const nsISoundPlayer = Components.interfaces.nsISoundPlayer;
|
||||
var soundPlayer =
|
||||
Components.classes["@mozilla.org/content/media/soundplayer;1"].
|
||||
getService(nsISoundPlayer);
|
||||
isnot(soundPlayer, null, "failed to get the shared sound player");
|
||||
|
||||
const nsISound = Components.interfaces.nsISound;
|
||||
var sound = Components.classes["@mozilla.org/sound;1"].getService(nsISound);
|
||||
isnot(sound, null, "failed to get the shared nsISound instance");
|
||||
|
||||
function getCurrentURL() {
|
||||
var url = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Components.interfaces.nsIIOService).
|
||||
newURI(location.href, null, null);
|
||||
url.QueryInterface(Components.interfaces.nsIURL);
|
||||
return url;
|
||||
}
|
||||
|
||||
// All tests should run asynchronously because some methods of the interfaces
|
||||
// play the sound in another thread.
|
||||
testSysSoundBeep();
|
||||
|
||||
const kDelay = 500;
|
||||
|
||||
function testSysSoundBeep()
|
||||
{
|
||||
ok(true, "running testSysSoundBeep...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sysSoundService.beep();
|
||||
|
||||
setTimeout(testSysSoundPlayAlias, kDelay);
|
||||
}
|
||||
|
||||
function testSysSoundPlayAlias()
|
||||
{
|
||||
ok(true, "running testSysSoundPlayAlias...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sysSoundService.playAlias("foobar");
|
||||
|
||||
setTimeout(testSysSoundPlayEventSound1, kDelay);
|
||||
}
|
||||
|
||||
function testSysSoundPlayEventSound1()
|
||||
{
|
||||
ok(true, "running testSysSoundPlayEventSound1...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
// EVENT_NEW_MAIL_RECEIVED is supported on all platforms now.
|
||||
sysSoundService.playEventSound(
|
||||
nsISystemSoundService.EVENT_NEW_MAIL_RECEIVED);
|
||||
|
||||
setTimeout(testSysSoundPlayEventSound2, kDelay);
|
||||
}
|
||||
|
||||
function testSysSoundPlayEventSound2()
|
||||
{
|
||||
ok(true, "running testSysSoundPlayEventSound2...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
// EVENT_SELECT_DIALOG_OPEN isn't supported on all platforms now.
|
||||
sysSoundService.playEventSound(
|
||||
nsISystemSoundService.EVENT_SELECT_DIALOG_OPEN);
|
||||
|
||||
setTimeout(createAnotherSystemSoundService, kDelay);
|
||||
}
|
||||
|
||||
function createAnotherSystemSoundService()
|
||||
{
|
||||
ok(true, "running createAnotherSystemSoundService...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var sysSound2 = Components.classes["@mozilla.org/systemsoundservice;1"].
|
||||
createInstance(nsISystemSoundService);
|
||||
isnot(sysSound2, null, "failed to create another nsISystemSoundService");
|
||||
// The createInstance should return the same instance as the service.
|
||||
// The implementation have to be singleton.
|
||||
is(sysSound2, sysSoundService, "the new instance is created");
|
||||
sysSound2.playEventSound(nsISystemSoundService.EVENT_NEW_MAIL_RECEIVED);
|
||||
|
||||
// The reference will be released, but it shouldn't release the instance.
|
||||
|
||||
setTimeout(testSoundPlayerPlay1, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlayerPlay1()
|
||||
{
|
||||
ok(true, "running testSoundPlayerPlay1...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var url = getCurrentURL();
|
||||
url.fileName = "r11025_u8_c1.wav";
|
||||
soundPlayer.play(url);
|
||||
|
||||
setTimeout(testSoundPlayerPlay2, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlayerPlay2()
|
||||
{
|
||||
ok(true, "running testSoundPlayerPlay2...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var url = getCurrentURL();
|
||||
url.fileName = "dont_be_this_file_name.wav";
|
||||
|
||||
soundPlayer.play(url);
|
||||
|
||||
setTimeout(testSoundPlayerStop, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlayerStop()
|
||||
{
|
||||
ok(true, "running testSoundPlayerStop...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
soundPlayer.stop();
|
||||
|
||||
setTimeout(createAnotherSoundPlayer, kDelay);
|
||||
}
|
||||
|
||||
function createAnotherSoundPlayer()
|
||||
{
|
||||
ok(true, "running createAnotherSoundPlayer...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var soundPlayer2 =
|
||||
Components.classes["@mozilla.org/content/media/soundplayer;1"].
|
||||
createInstance(nsISoundPlayer);
|
||||
isnot(soundPlayer2, null, "failed to create another sound player");
|
||||
// The createInstance should return the same instance as the service.
|
||||
// The implementation have to be singleton.
|
||||
is(soundPlayer2, soundPlayer, "new sound player instance is created");
|
||||
var url = getCurrentURL();
|
||||
url.fileName = "r11025_u8_c1.wav";
|
||||
soundPlayer2.play(url);
|
||||
|
||||
// The reference will be released, but it shouldn't release the instance.
|
||||
|
||||
setTimeout(testSoundPlay, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlay()
|
||||
{
|
||||
ok(true, "running testSoundPlay...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
var url = getCurrentURL();
|
||||
url.fileName = "r11025_u8_c1.wav";
|
||||
sound.play(url);
|
||||
|
||||
setTimeout(testSoundPlaySystemSound1, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlaySystemSound1()
|
||||
{
|
||||
ok(true, "running testSoundPlaySystemSound1...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.playSystemSound("foobar");
|
||||
|
||||
setTimeout(testSoundPlaySystemSound2, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlaySystemSound2()
|
||||
{
|
||||
ok(true, "running testSoundPlaySystemSound2...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.playSystemSound("_moz_mailbeep");
|
||||
|
||||
setTimeout(testSoundPlaySystemSound3, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlaySystemSound3()
|
||||
{
|
||||
ok(true, "running testSoundPlaySystemSound3...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.playSystemSound("_moz_selectdialog");
|
||||
|
||||
setTimeout(testSoundBeep, kDelay);
|
||||
}
|
||||
|
||||
function testSoundBeep()
|
||||
{
|
||||
ok(true, "running testSoundBeep...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.beep();
|
||||
|
||||
setTimeout(testSoundPlayEventSound1, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlayEventSound1()
|
||||
{
|
||||
ok(true, "running testPlayEventSound1...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.playEventSound(nsISound.EVENT_NEW_MAIL_RECEIVED);
|
||||
|
||||
setTimeout(testSoundPlayEventSound2, kDelay);
|
||||
}
|
||||
|
||||
function testSoundPlayEventSound2()
|
||||
{
|
||||
ok(true, "running testSoundPlayEventSound2...");
|
||||
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
||||
sound.playEventSound(nsISound.EVENT_SELECT_DIALOG_OPEN);
|
||||
|
||||
setTimeout(SimpleTest.finish, kDelay);
|
||||
}
|
||||
}
|
||||
|
||||
]]>
|
||||
</script>
|
||||
|
||||
</window>
|
||||
|
|
@ -53,7 +53,6 @@
|
|||
#include "nsIStringBundle.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsISystemSoundService.h"
|
||||
|
||||
static const char kPromptURL[] = "chrome://global/content/commonDialog.xul";
|
||||
static const char kSelectPromptURL[] = "chrome://global/content/selectDialog.xul";
|
||||
|
|
@ -141,7 +140,7 @@ nsPromptService::Alert(nsIDOMWindow *parent,
|
|||
NS_ConvertASCIItoUTF16 styleClass(kAlertIconClass);
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_ALERT_DIALOG.get());
|
||||
block->SetInt(eSoundEventId, nsISystemSoundService::EVENT_ALERT_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_ALERT_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
|
||||
|
|
@ -187,7 +186,7 @@ nsPromptService::AlertCheck(nsIDOMWindow *parent,
|
|||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_ALERT_DIALOG.get());
|
||||
block->SetInt(eSoundEventId, nsISystemSoundService::EVENT_ALERT_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_ALERT_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -234,8 +233,7 @@ nsPromptService::Confirm(nsIDOMWindow *parent,
|
|||
NS_ConvertASCIItoUTF16 styleClass(kQuestionIconClass);
|
||||
block->SetString(eIconClass, styleClass.get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get());
|
||||
block->SetInt(eSoundEventId,
|
||||
nsISystemSoundService::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -286,8 +284,7 @@ nsPromptService::ConfirmCheck(nsIDOMWindow *parent,
|
|||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
block->SetInt(eCheckboxState, *checkValue);
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get());
|
||||
block->SetInt(eSoundEventId,
|
||||
nsISystemSoundService::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -390,8 +387,7 @@ nsPromptService::ConfirmEx(nsIDOMWindow *parent,
|
|||
|
||||
block->SetString(eIconClass, NS_ConvertASCIItoUTF16(kQuestionIconClass).get());
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_CONFIRM_DIALOG.get());
|
||||
block->SetInt(eSoundEventId,
|
||||
nsISystemSoundService::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_CONFIRM_DIALOG_OPEN);
|
||||
|
||||
if (checkMsg && checkValue) {
|
||||
block->SetString(eCheckboxMsg, checkMsg);
|
||||
|
|
@ -468,7 +464,7 @@ nsPromptService::Prompt(nsIDOMWindow *parent,
|
|||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get());
|
||||
block->SetInt(eSoundEventId, nsISystemSoundService::EVENT_PROMPT_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -545,7 +541,7 @@ nsPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
|
|||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get());
|
||||
block->SetInt(eSoundEventId, nsISystemSoundService::EVENT_PROMPT_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -626,7 +622,7 @@ NS_IMETHODIMP nsPromptService::PromptPassword(nsIDOMWindow *parent,
|
|||
block->SetInt(eCheckboxState, *checkValue);
|
||||
}
|
||||
block->SetString(eOpeningSound, NS_SYSSOUND_PROMPT_DIALOG.get());
|
||||
block->SetInt(eSoundEventId, nsISystemSoundService::EVENT_PROMPT_DIALOG_OPEN);
|
||||
block->SetInt(eSoundEventId, nsISound::EVENT_PROMPT_DIALOG_OPEN);
|
||||
|
||||
rv = DoDialog(parent, block, kPromptURL);
|
||||
if (NS_FAILED(rv))
|
||||
|
|
@ -762,8 +758,7 @@ nsPromptService::ShowNonBlockingAlert(nsIDOMWindow *aParent,
|
|||
paramBlock->SetString(eDialogTitle, aDialogTitle);
|
||||
paramBlock->SetString(eMsg, aText);
|
||||
paramBlock->SetString(eOpeningSound, NS_SYSSOUND_ALERT_DIALOG.get());
|
||||
paramBlock->SetInt(eSoundEventId,
|
||||
nsISystemSoundService::EVENT_ALERT_DIALOG_OPEN);
|
||||
paramBlock->SetInt(eSoundEventId, nsISound::EVENT_ALERT_DIALOG_OPEN);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> dialog;
|
||||
mWatcher->OpenWindow(aParent, "chrome://global/content/commonDialog.xul",
|
||||
|
|
|
|||
|
|
@ -99,7 +99,6 @@
|
|||
#include "nsStyleSheetService.h"
|
||||
#include "nsXULPopupManager.h"
|
||||
#include "nsFocusManager.h"
|
||||
#include "nsSoundPlayer.h"
|
||||
|
||||
#include "nsIEventListenerService.h"
|
||||
// Transformiix stuff
|
||||
|
|
@ -296,8 +295,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMFileRequest, Init)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMParser)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDOMStorageManager,
|
||||
nsDOMStorageManager::GetInstance)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSoundPlayer,
|
||||
nsSoundPlayer::GetInstance)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1072,11 +1069,6 @@ static const nsModuleComponentInfo gComponents[] = {
|
|||
UnregisterHTMLAudioElement },
|
||||
#endif
|
||||
|
||||
{ "Sound player",
|
||||
NS_SOUNDPLAYER_CID,
|
||||
"@mozilla.org/content/media/soundplayer;1",
|
||||
nsSoundPlayerConstructor },
|
||||
|
||||
{ "Canvas 2D Rendering Context",
|
||||
NS_CANVASRENDERINGCONTEXT2D_CID,
|
||||
"@mozilla.org/content/canvas-rendering-context;1?id=2d",
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsCSSFrameConstructor.h"
|
||||
#ifdef XP_WIN
|
||||
#include "nsISystemSoundService.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#endif
|
||||
#include "nsContentUtils.h"
|
||||
|
|
@ -266,7 +266,9 @@ nsMenuBarFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent)
|
|||
#ifdef XP_WIN
|
||||
// behavior on Windows - this item is on the menu bar, beep and deactivate the menu bar
|
||||
if (mIsActive) {
|
||||
nsContentUtils::PlayEventSound(nsISystemSoundService::EVENT_MENU_NOT_FOUND);
|
||||
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (soundInterface)
|
||||
soundInterface->Beep();
|
||||
}
|
||||
|
||||
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsDisplayList.h"
|
||||
#include "nsIReflowCallback.h"
|
||||
#include "nsISystemSoundService.h"
|
||||
#include "nsISound.h"
|
||||
|
||||
#define NS_MENU_POPUP_LIST_INDEX 0
|
||||
|
||||
|
|
@ -1174,7 +1174,9 @@ nsMenuFrame::Execute(nsGUIEvent *aEvent)
|
|||
}
|
||||
}
|
||||
|
||||
nsContentUtils::PlayEventSound(nsISystemSoundService::EVENT_MENU_EXECUTE);
|
||||
nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
|
||||
if (sound)
|
||||
sound->PlayEventSound(nsISound::EVENT_MENU_EXECUTE);
|
||||
|
||||
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
||||
if (pm && mMenuParent)
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@
|
|||
#include "nsBindingManager.h"
|
||||
#include "nsIDocShellTreeOwner.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsISystemSoundService.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIRootBox.h"
|
||||
#include "nsIScreenManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
|
@ -637,7 +637,9 @@ nsMenuPopupFrame::ShowPopup(PRBool aIsContextMenu, PRBool aSelectFirstItem)
|
|||
NS_FRAME_HAS_DIRTY_CHILDREN);
|
||||
}
|
||||
if (mPopupType == ePopupTypeMenu) {
|
||||
nsContentUtils::PlayEventSound(nsISystemSoundService::EVENT_MENU_POPUP);
|
||||
nsCOMPtr<nsISound> sound(do_CreateInstance("@mozilla.org/sound;1"));
|
||||
if (sound)
|
||||
sound->PlayEventSound(nsISound::EVENT_MENU_POPUP);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1328,8 +1330,11 @@ nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, PRBool& doActi
|
|||
return nsnull;
|
||||
}
|
||||
else {
|
||||
nsContentUtils::PlayEventSound(
|
||||
nsISystemSoundService::EVENT_MENU_NOT_FOUND);
|
||||
#ifdef XP_WIN
|
||||
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (soundInterface)
|
||||
soundInterface->Beep();
|
||||
#endif // #ifdef XP_WIN
|
||||
}
|
||||
}
|
||||
return nsnull;
|
||||
|
|
@ -1444,12 +1449,15 @@ nsMenuPopupFrame::FindMenuWithShortcut(nsIDOMKeyEvent* aKeyEvent, PRBool& doActi
|
|||
mIncrementalString.SetLength(mIncrementalString.Length() - 1);
|
||||
|
||||
// didn't find a matching menu item
|
||||
|
||||
// this item is in a menu popup off of the menu bar, so beep and do nothing
|
||||
// else
|
||||
#ifdef XP_WIN
|
||||
// behavior on Windows - this item is in a menu popup off of the
|
||||
// menu bar, so beep and do nothing else
|
||||
if (isMenu) {
|
||||
nsContentUtils::PlayEventSound(nsISystemSoundService::EVENT_MENU_NOT_FOUND);
|
||||
nsCOMPtr<nsISound> soundInterface = do_CreateInstance("@mozilla.org/sound;1");
|
||||
if (soundInterface)
|
||||
soundInterface->Beep();
|
||||
}
|
||||
#endif // #ifdef XP_WIN
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,8 +238,8 @@ function commonDialogOnLoad()
|
|||
try {
|
||||
var sound = gCommonDialogParam.GetInt(7);
|
||||
if (sound) {
|
||||
Cc["@mozilla.org/systemsoundservice;1"]
|
||||
.getService(Ci.nsISystemSoundService)
|
||||
Cc["@mozilla.org/sound;1"]
|
||||
.createInstance(Ci.nsISound)
|
||||
.playEventSound(sound);
|
||||
}
|
||||
} catch (e) { }
|
||||
|
|
|
|||
|
|
@ -101,10 +101,10 @@ function selectDialogOnLoad() {
|
|||
|
||||
// play sound
|
||||
try {
|
||||
const nsISystemSoundService = Components.interfaces.nsISystemSoundService;
|
||||
Components.classes["@mozilla.org/systemsoundservice;1"]
|
||||
.getService(nsISystemSoundService)
|
||||
.playEventSound(nsISystemSoundService.EVENT_SELECT_DIALOG_OPEN);
|
||||
const nsISound = Components.interfaces.nsISound;
|
||||
Components.classes["@mozilla.org/sound;1"]
|
||||
.createInstance(nsISound)
|
||||
.playEventSound(nsISound.EVENT_SELECT_DIALOG_OPEN);
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ XPIDLSRCS = \
|
|||
nsIFilePicker.idl \
|
||||
nsIToolkit.idl \
|
||||
nsISound.idl \
|
||||
nsISystemSoundService.idl \
|
||||
nsITransferable.idl \
|
||||
nsIClipboardDragDropHooks.idl \
|
||||
nsIClipboardDragDropHookList.idl \
|
||||
|
|
|
|||
|
|
@ -41,13 +41,6 @@
|
|||
|
||||
interface nsIURL;
|
||||
|
||||
/**
|
||||
* WARNING: nsISound is now OBSOLETE.
|
||||
*
|
||||
* nsISound instance just delegates the methods to nsISystemSoundService and
|
||||
* nsISoundPlayer. You should use the new interfaces directly.
|
||||
*/
|
||||
|
||||
[scriptable, uuid(86B75B05-DB60-4c3e-97A7-82B363A41A01)]
|
||||
interface nsISound : nsISupports
|
||||
{
|
||||
|
|
@ -62,8 +55,9 @@ interface nsISound : nsISupports
|
|||
void beep();
|
||||
|
||||
/**
|
||||
* init() doesn't do anything now.
|
||||
*/
|
||||
* Not strictly necessary, but avoids delay before first sound.
|
||||
* The various methods on nsISound call Init() if they need to.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,79 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(A8948ACA-0C2F-45b2-A4BB-3ED30006EAA4)]
|
||||
interface nsISystemSoundService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Plays the system beep.
|
||||
*/
|
||||
void beep();
|
||||
|
||||
/**
|
||||
* Play the platform's sound with the given alias name. Names and supported
|
||||
* sounds are platform specific. _moz_ alias names are not supported.
|
||||
*/
|
||||
void playAlias(in AString aSoundAlias);
|
||||
|
||||
/**
|
||||
* In some situations, playEventSound will be called. Then, each
|
||||
* implementations will play a system sound for the event if it's necessary.
|
||||
*
|
||||
* NOTE: Don't change these values because they are used in
|
||||
* nsPIPromptService.idl. So, if they are changed, that makes big impact for
|
||||
* the embedders.
|
||||
*
|
||||
* And also they are must be same as the definition in nsISound, however,
|
||||
* when you add new event, you don't need to add the same consts to the
|
||||
* nsISound because the it's obsolete.
|
||||
*/
|
||||
const unsigned long EVENT_NEW_MAIL_RECEIVED = 0;
|
||||
const unsigned long EVENT_ALERT_DIALOG_OPEN = 1;
|
||||
const unsigned long EVENT_CONFIRM_DIALOG_OPEN = 2;
|
||||
const unsigned long EVENT_PROMPT_DIALOG_OPEN = 3;
|
||||
const unsigned long EVENT_SELECT_DIALOG_OPEN = 4;
|
||||
const unsigned long EVENT_MENU_EXECUTE = 5;
|
||||
const unsigned long EVENT_MENU_POPUP = 6;
|
||||
const unsigned long EVENT_MENU_NOT_FOUND = 7;
|
||||
|
||||
void playEventSound(in unsigned long aEventID);
|
||||
};
|
||||
|
||||
|
|
@ -123,10 +123,6 @@
|
|||
#define NS_SOUND_CID \
|
||||
{ 0xb148eed2, 0x236d, 0x11d3, { 0xb3, 0x5c, 0x0, 0xa0, 0xcc, 0x3c, 0x1c, 0xde } }
|
||||
|
||||
// {F932EFC3-DD10-4d13-80BE-2790609AD9AE}
|
||||
#define NS_SYSTEM_SOUND_SERVICE_CID \
|
||||
{ 0xf932efc3, 0xdd10, 0x4d13, { 0x80, 0xbe, 0x27, 0x90, 0x60, 0x9a, 0xd9, 0xae } }
|
||||
|
||||
// {9f1800ab-f428-4207-b40c-e832e77b01fc}
|
||||
#define NS_BIDIKEYBOARD_CID \
|
||||
{ 0x9f1800ab, 0xf428, 0x4207, { 0xb4, 0x0c, 0xe8, 0x32, 0xe7, 0x7b, 0x01, 0xfc } }
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ CPPSRCS = \
|
|||
nsDragService.cpp \
|
||||
nsFilePicker.cpp \
|
||||
nsLookAndFeel.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
nsToolkit.cpp \
|
||||
nsWidgetFactory.cpp \
|
||||
nsWindow.cpp \
|
||||
|
|
|
|||
179
widget/src/beos/nsSound.cpp
Normal file
179
widget/src/beos/nsSound.cpp
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
#include "plstr.h"
|
||||
#include <stdio.h>
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
|
||||
#include <OS.h>
|
||||
#include <SimpleGameSound.h>
|
||||
#include <Beep.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsSound::nsSound()
|
||||
: mSound(0)
|
||||
{
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
// print a load error on bad status
|
||||
if (NS_FAILED(aStatus))
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf("Failed load sound file");
|
||||
#endif
|
||||
return aStatus;
|
||||
}
|
||||
// In theory, BeOS can play any sound format supported by MediaKit,
|
||||
// we can also play it from data, but it needs parsing format and
|
||||
// providing it to sound player, so let MediaKit to do it by self
|
||||
static const char kSoundTmpFileName[] = "mozsound";
|
||||
nsCOMPtr<nsIFile> soundTmp;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(soundTmp));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = soundTmp->AppendNative(nsDependentCString(kSoundTmpFileName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCAutoString soundFilename;
|
||||
(void) soundTmp->GetNativePath(soundFilename);
|
||||
FILE *fp = fopen(soundFilename.get(), "wb+");
|
||||
#ifdef DEBUG
|
||||
printf("Playing sound file%s\n",soundFilename.get());
|
||||
#endif
|
||||
if (fp)
|
||||
{
|
||||
fwrite(data, 1, dataLen, fp);
|
||||
fflush(fp);
|
||||
fclose(fp);
|
||||
Init();
|
||||
mSound = new BSimpleGameSound(soundFilename.get());
|
||||
if (mSound != NULL && mSound->InitCheck() == B_OK)
|
||||
{
|
||||
mSound->SetIsLooping(false);
|
||||
mSound->StartPlaying();
|
||||
rv = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
unlink(soundFilename.get());
|
||||
}
|
||||
else
|
||||
{
|
||||
return Beep();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::Init(void)
|
||||
{
|
||||
if (mSound)
|
||||
{
|
||||
mSound->StopPlaying();
|
||||
delete mSound;
|
||||
mSound = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Beep()
|
||||
{
|
||||
::beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
return Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
nsCOMPtr <nsIURI> fileURI;
|
||||
// create a nsILocalFile and then a nsIFileURL from that
|
||||
nsCOMPtr <nsILocalFile> soundFile;
|
||||
rv = NS_NewLocalFile(aSoundAlias, PR_TRUE,
|
||||
getter_AddRefs(soundFile));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = Play(fileURL);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
return aEventId == EVENT_NEW_MAIL_RECEIVED ? Beep() : NS_OK;
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -36,23 +35,26 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
class BSimpleGameSound;
|
||||
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
private:
|
||||
BSimpleGameSound *mSound;
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
|
||||
#include <OS.h>
|
||||
#include <SimpleGameSound.h>
|
||||
#include <Beep.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
::beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (aEventID == EVENT_NEW_MAIL_RECEIVED) {
|
||||
StopSoundPlayer();
|
||||
return Beep();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -49,7 +49,6 @@
|
|||
#include "nsPopupWindow.h"
|
||||
#include "nsChildView.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsAppShell.h"
|
||||
#include "nsAppShellSingleton.h"
|
||||
|
|
@ -82,8 +81,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerBeOS)
|
||||
|
|
@ -139,10 +136,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "BeOS Drag Service",
|
||||
NS_DRAGSERVICE_CID,
|
||||
"@mozilla.org/widget/dragservice;1",
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@
|
|||
#include "nsNativeThemeWin.h"
|
||||
#include "nsScreenManagerWin.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsToolkit.h"
|
||||
#include "nsWindow.h"
|
||||
#include "WinTaskbar.h"
|
||||
|
|
@ -92,8 +91,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceWin)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
|
||||
#if MOZ_WINSDK_TARGETVER >= MOZ_NTDDI_WIN7
|
||||
using namespace mozilla::widget;
|
||||
|
|
@ -170,10 +167,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "Transferable",
|
||||
NS_TRANSFERABLE_CID,
|
||||
"@mozilla.org/widget/transferable;1",
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ CMMSRCS = \
|
|||
nsMacCursor.mm \
|
||||
nsScreenCocoa.mm \
|
||||
nsScreenManagerCocoa.mm \
|
||||
nsSystemSoundService.mm \
|
||||
nsSound.mm \
|
||||
nsLookAndFeel.mm \
|
||||
nsNativeThemeCocoa.mm \
|
||||
nsDeviceContextSpecX.mm \
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart@mozilla.com>
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -39,24 +38,22 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef nsSound_h_
|
||||
#define nsSound_h_
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayAlias(const nsAString &aSoundAlias);
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
};
|
||||
|
||||
#endif // __nsSystemSoundService_h__
|
||||
#endif // nsSound_h_
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart@mozilla.com>
|
||||
* Vladimir Vukicevic <vladimir@pobox.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -39,36 +38,30 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsObjCExceptions.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
nsSound::nsSound()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
nsSound::Beep()
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NSBeep();
|
||||
return NS_OK;
|
||||
|
||||
|
|
@ -76,18 +69,56 @@ nsSystemSoundService::Beep()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayAlias(const nsAString &aSoundAlias)
|
||||
nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayAlias(aSoundAlias);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NSData *value = [NSData dataWithBytes:data length:dataLen];
|
||||
|
||||
NSSound *sound = [[NSSound alloc] initWithData:value];
|
||||
|
||||
[sound play];
|
||||
|
||||
[sound autorelease];
|
||||
|
||||
return NS_OK;
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsCOMPtr<nsIURI> uri(do_QueryInterface(aURL));
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
return NS_NewStreamLoader(getter_AddRefs(loader), uri, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
|
||||
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
// Mac doesn't have system sound settings for each user actions.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NSString *name = [NSString stringWithCharacters:aSoundAlias.BeginReading()
|
||||
length:aSoundAlias.Length()];
|
||||
NSSound *sound = [NSSound soundNamed:name];
|
||||
if (sound) {
|
||||
StopSoundPlayer();
|
||||
[sound stop];
|
||||
[sound play];
|
||||
}
|
||||
|
|
@ -98,11 +129,8 @@ nsSystemSoundService::PlayAlias(const nsAString &aSoundAlias)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Mac doesn't have system sound settings for each user actions.
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -59,7 +59,6 @@
|
|||
|
||||
#include "nsAccelerometerX.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsIdleServiceX.h"
|
||||
|
||||
#include "nsScreenManagerCocoa.h"
|
||||
|
|
@ -74,8 +73,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAccelerometerX)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
|
|
@ -132,10 +129,6 @@ static const nsModuleComponentInfo gComponents[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "Accelerometer",
|
||||
NS_ACCELEROMETER_CID,
|
||||
NS_ACCELEROMETER_CONTRACTID,
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ CPPSRCS = \
|
|||
nsLookAndFeel.cpp \
|
||||
nsGtkKeyUtils.cpp \
|
||||
nsFilePicker.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
nsNativeKeyBindings.cpp \
|
||||
nsScreenGtk.cpp \
|
||||
nsScreenManagerGtk.cpp \
|
||||
|
|
|
|||
545
widget/src/gtk2/nsSound.cpp
Normal file
545
widget/src/gtk2/nsSound.cpp
Normal file
|
|
@ -0,0 +1,545 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "plstr.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#include "nsSound.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
/* used with esd_open_sound */
|
||||
static int esdref = -1;
|
||||
static PRLibrary *elib = nsnull;
|
||||
static PRLibrary *libcanberra = nsnull;
|
||||
static PRLibrary* libasound = nsnull;
|
||||
|
||||
// the following from esd.h
|
||||
|
||||
#define ESD_BITS8 (0x0000)
|
||||
#define ESD_BITS16 (0x0001)
|
||||
#define ESD_MONO (0x0010)
|
||||
#define ESD_STEREO (0x0020)
|
||||
#define ESD_STREAM (0x0000)
|
||||
#define ESD_PLAY (0x1000)
|
||||
|
||||
#define WAV_MIN_LENGTH 44
|
||||
|
||||
typedef int (*EsdOpenSoundType)(const char *host);
|
||||
typedef int (*EsdCloseType)(int);
|
||||
|
||||
/* used to play the sounds from the find symbol call */
|
||||
typedef int (*EsdPlayStreamType) (int, int, const char *, const char *);
|
||||
typedef int (*EsdAudioOpenType) (void);
|
||||
typedef int (*EsdAudioWriteType) (const void *, int);
|
||||
typedef void (*EsdAudioCloseType) (void);
|
||||
|
||||
/* used to find and play common system event sounds.
|
||||
this interfaces with libcanberra.
|
||||
*/
|
||||
typedef struct _ca_context ca_context;
|
||||
|
||||
typedef int (*ca_context_create_fn) (ca_context **);
|
||||
typedef int (*ca_context_destroy_fn) (ca_context *);
|
||||
typedef int (*ca_context_play_fn) (ca_context *c,
|
||||
uint32_t id,
|
||||
...);
|
||||
typedef int (*ca_context_change_props_fn) (ca_context *c,
|
||||
...);
|
||||
|
||||
static ca_context_create_fn ca_context_create;
|
||||
static ca_context_destroy_fn ca_context_destroy;
|
||||
static ca_context_play_fn ca_context_play;
|
||||
static ca_context_change_props_fn ca_context_change_props;
|
||||
|
||||
/* we provide a blank error handler to silence ALSA's stderr
|
||||
messages on computers with no sound devices */
|
||||
typedef void (*snd_lib_error_handler_t) (const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
int err,
|
||||
const char* format,
|
||||
...);
|
||||
typedef int (*snd_lib_error_set_handler_fn) (snd_lib_error_handler_t handler);
|
||||
|
||||
static void
|
||||
quiet_error_handler(const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
int err,
|
||||
const char* format,
|
||||
...)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsSound::nsSound()
|
||||
{
|
||||
mInited = PR_FALSE;
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
if (esdref >= 0) {
|
||||
EsdCloseType EsdClose = (EsdCloseType) PR_FindFunctionSymbol(elib, "esd_close");
|
||||
if (EsdClose)
|
||||
(*EsdClose)(esdref);
|
||||
esdref = -1;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Init()
|
||||
{
|
||||
// This function is designed so that no library is compulsory, and
|
||||
// one library missing doesn't cause the other(s) to not be used.
|
||||
if (mInited)
|
||||
return NS_OK;
|
||||
|
||||
mInited = PR_TRUE;
|
||||
|
||||
if (!elib) {
|
||||
elib = PR_LoadLibrary("libesd.so.0");
|
||||
if (elib) {
|
||||
EsdOpenSoundType EsdOpenSound =
|
||||
(EsdOpenSoundType) PR_FindFunctionSymbol(elib, "esd_open_sound");
|
||||
if (!EsdOpenSound) {
|
||||
PR_UnloadLibrary(elib);
|
||||
elib = nsnull;
|
||||
} else {
|
||||
esdref = (*EsdOpenSound)("localhost");
|
||||
if (esdref < 0) {
|
||||
PR_UnloadLibrary(elib);
|
||||
elib = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!libasound) {
|
||||
PRFuncPtr func = PR_FindFunctionSymbolAndLibrary("snd_lib_error_set_handler",
|
||||
&libasound);
|
||||
if (libasound) {
|
||||
snd_lib_error_set_handler_fn snd_lib_error_set_handler =
|
||||
(snd_lib_error_set_handler_fn) func;
|
||||
snd_lib_error_set_handler(quiet_error_handler);
|
||||
}
|
||||
}
|
||||
|
||||
if (!libcanberra) {
|
||||
libcanberra = PR_LoadLibrary("libcanberra.so.0");
|
||||
if (libcanberra) {
|
||||
ca_context_create = (ca_context_create_fn) PR_FindFunctionSymbol(libcanberra, "ca_context_create");
|
||||
if (!ca_context_create) {
|
||||
PR_UnloadLibrary(libcanberra);
|
||||
libcanberra = nsnull;
|
||||
} else {
|
||||
// at this point we know we have a good libcanberra library
|
||||
ca_context_destroy = (ca_context_destroy_fn) PR_FindFunctionSymbol(libcanberra, "ca_context_destroy");
|
||||
ca_context_play = (ca_context_play_fn) PR_FindFunctionSymbol(libcanberra, "ca_context_play");
|
||||
ca_context_change_props = (ca_context_change_props_fn) PR_FindFunctionSymbol(libcanberra, "ca_context_change_props");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsSound::Shutdown()
|
||||
{
|
||||
if (elib) {
|
||||
PR_UnloadLibrary(elib);
|
||||
elib = nsnull;
|
||||
}
|
||||
if (libcanberra) {
|
||||
PR_UnloadLibrary(libcanberra);
|
||||
libcanberra = nsnull;
|
||||
}
|
||||
if (libasound) {
|
||||
PR_UnloadLibrary(libasound);
|
||||
libasound = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
#define GET_WORD(s, i) (s[i+1] << 8) | s[i]
|
||||
#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i]
|
||||
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
|
||||
// print a load error on bad status, and return
|
||||
if (NS_FAILED(aStatus)) {
|
||||
#ifdef DEBUG
|
||||
if (aLoader) {
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
aLoader->GetRequest(getter_AddRefs(request));
|
||||
if (request) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
||||
if (channel) {
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
if (uri) {
|
||||
nsCAutoString uriSpec;
|
||||
uri->GetSpec(uriSpec);
|
||||
printf("Failed to load %s\n", uriSpec.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
int fd, mask = 0;
|
||||
PRUint32 samples_per_sec = 0, avg_bytes_per_sec = 0, chunk_len = 0;
|
||||
PRUint16 format, channels = 1, bits_per_sample = 0;
|
||||
const PRUint8 *audio = nsnull;
|
||||
size_t audio_len = 0;
|
||||
|
||||
if (dataLen < 4) {
|
||||
NS_WARNING("Sound stream too short to determine its type");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (memcmp(data, "RIFF", 4)) {
|
||||
#ifdef DEBUG
|
||||
printf("We only support WAV files currently.\n");
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (dataLen <= WAV_MIN_LENGTH) {
|
||||
NS_WARNING("WAV files should be longer than 44 bytes.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRUint32 i = 12;
|
||||
while (i + 7 < dataLen) {
|
||||
if (!memcmp(data + i, "fmt ", 4) && !chunk_len) {
|
||||
i += 4;
|
||||
|
||||
/* length of the rest of this subblock (should be 16 for PCM data */
|
||||
chunk_len = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
if (chunk_len < 16 || i + chunk_len >= dataLen) {
|
||||
NS_WARNING("Invalid WAV file: bad fmt chunk.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
format = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
channels = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
samples_per_sec = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
avg_bytes_per_sec = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
// block align
|
||||
i += 2;
|
||||
|
||||
bits_per_sample = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
/* we don't support WAVs with odd compression codes */
|
||||
if (chunk_len != 16)
|
||||
NS_WARNING("Extra format bits found in WAV. Ignoring");
|
||||
|
||||
i += chunk_len - 16;
|
||||
} else if (!memcmp(data + i, "data", 4)) {
|
||||
i += 4;
|
||||
if (!chunk_len) {
|
||||
NS_WARNING("Invalid WAV file: no fmt chunk found");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
audio_len = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
/* try to play truncated WAVs */
|
||||
if (i + audio_len > dataLen)
|
||||
audio_len = dataLen - i;
|
||||
|
||||
audio = data + i;
|
||||
break;
|
||||
} else {
|
||||
i += 4;
|
||||
i += GET_DWORD(data, i);
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (!audio) {
|
||||
NS_WARNING("Invalid WAV file: no data chunk found");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* No audio data? well, at least the WAV was valid. */
|
||||
if (!audio_len)
|
||||
return NS_OK;
|
||||
|
||||
#if 0
|
||||
printf("f: %d | c: %d | sps: %li | abps: %li | ba: %d | bps: %d | rate: %li\n",
|
||||
format, channels, samples_per_sec, avg_bytes_per_sec, block_align, bits_per_sample, rate);
|
||||
#endif
|
||||
|
||||
/* open up connection to esd */
|
||||
EsdPlayStreamType EsdPlayStream =
|
||||
(EsdPlayStreamType) PR_FindFunctionSymbol(elib,
|
||||
"esd_play_stream");
|
||||
if (!EsdPlayStream)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mask = ESD_PLAY | ESD_STREAM;
|
||||
|
||||
if (bits_per_sample == 8)
|
||||
mask |= ESD_BITS8;
|
||||
else
|
||||
mask |= ESD_BITS16;
|
||||
|
||||
if (channels == 1)
|
||||
mask |= ESD_MONO;
|
||||
else
|
||||
mask |= ESD_STEREO;
|
||||
|
||||
nsAutoArrayPtr<PRUint8> buf;
|
||||
|
||||
// ESD only handle little-endian data.
|
||||
// Swap the byte order if we're on a big-endian architecture.
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
if (bits_per_sample != 8) {
|
||||
buf = new PRUint8[audio_len];
|
||||
if (!buf)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
for (PRUint32 j = 0; j + 2 < audio_len; j += 2) {
|
||||
buf[j] = audio[j + 1];
|
||||
buf[j + 1] = audio[j];
|
||||
}
|
||||
|
||||
audio = buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
fd = (*EsdPlayStream)(mask, samples_per_sec, NULL, "mozillaSound");
|
||||
|
||||
if (fd < 0) {
|
||||
int *esd_audio_format = (int *) PR_FindSymbol(elib, "esd_audio_format");
|
||||
int *esd_audio_rate = (int *) PR_FindSymbol(elib, "esd_audio_rate");
|
||||
EsdAudioOpenType EsdAudioOpen = (EsdAudioOpenType) PR_FindFunctionSymbol(elib, "esd_audio_open");
|
||||
EsdAudioWriteType EsdAudioWrite = (EsdAudioWriteType) PR_FindFunctionSymbol(elib, "esd_audio_write");
|
||||
EsdAudioCloseType EsdAudioClose = (EsdAudioCloseType) PR_FindFunctionSymbol(elib, "esd_audio_close");
|
||||
|
||||
if (!esd_audio_format || !esd_audio_rate ||
|
||||
!EsdAudioOpen || !EsdAudioWrite || !EsdAudioClose)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*esd_audio_format = mask;
|
||||
*esd_audio_rate = samples_per_sec;
|
||||
fd = (*EsdAudioOpen)();
|
||||
|
||||
if (fd < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
(*EsdAudioWrite)(audio, audio_len);
|
||||
(*EsdAudioClose)();
|
||||
} else {
|
||||
while (audio_len > 0) {
|
||||
ssize_t written = write(fd, audio, audio_len);
|
||||
if (written <= 0)
|
||||
break;
|
||||
audio += written;
|
||||
audio_len -= written;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Beep()
|
||||
{
|
||||
::gdk_beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!mInited)
|
||||
Init();
|
||||
|
||||
if (!elib)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
if (!mInited)
|
||||
Init();
|
||||
|
||||
if (!libcanberra)
|
||||
return NS_OK;
|
||||
|
||||
// Do we even want alert sounds?
|
||||
// If so, what sound theme are we using?
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
gchar* sound_theme_name = nsnull;
|
||||
|
||||
if (g_object_class_find_property(G_OBJECT_GET_CLASS(settings), "gtk-sound-theme-name") &&
|
||||
g_object_class_find_property(G_OBJECT_GET_CLASS(settings), "gtk-enable-event-sounds")) {
|
||||
gboolean enable_sounds = TRUE;
|
||||
g_object_get(settings, "gtk-enable-event-sounds", &enable_sounds,
|
||||
"gtk-sound-theme-name", &sound_theme_name,
|
||||
NULL);
|
||||
|
||||
if (!enable_sounds) {
|
||||
g_free(sound_theme_name);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// This allows us to avoid race conditions with freeing the context by handing that
|
||||
// responsibility to Glib, and still use one context at a time
|
||||
ca_context* ctx = nsnull;
|
||||
static GStaticPrivate ctx_static_private = G_STATIC_PRIVATE_INIT;
|
||||
ctx = (ca_context*) g_static_private_get(&ctx_static_private);
|
||||
if (!ctx) {
|
||||
ca_context_create(&ctx);
|
||||
if (!ctx) {
|
||||
g_free(sound_theme_name);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
g_static_private_set(&ctx_static_private, ctx, (GDestroyNotify) ca_context_destroy);
|
||||
}
|
||||
|
||||
if (sound_theme_name) {
|
||||
ca_context_change_props(ctx, "canberra.xdg-theme.name", sound_theme_name, NULL);
|
||||
g_free(sound_theme_name);
|
||||
}
|
||||
|
||||
switch (aEventId) {
|
||||
case EVENT_ALERT_DIALOG_OPEN:
|
||||
ca_context_play(ctx, 0, "event.id", "dialog-warning", NULL);
|
||||
break;
|
||||
case EVENT_CONFIRM_DIALOG_OPEN:
|
||||
ca_context_play(ctx, 0, "event.id", "dialog-question", NULL);
|
||||
break;
|
||||
case EVENT_NEW_MAIL_RECEIVED:
|
||||
ca_context_play(ctx, 0, "event.id", "message-new-email", NULL);
|
||||
break;
|
||||
case EVENT_MENU_EXECUTE:
|
||||
ca_context_play(ctx, 0, "event.id", "menu-click", NULL);
|
||||
break;
|
||||
case EVENT_MENU_POPUP:
|
||||
ca_context_play(ctx, 0, "event.id", "menu-popup", NULL);
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
PRUint32 eventId;
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
|
||||
eventId = EVENT_ALERT_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
|
||||
eventId = EVENT_CONFIRM_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
eventId = EVENT_NEW_MAIL_RECEIVED;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_EXECUTE))
|
||||
eventId = EVENT_MENU_EXECUTE;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP))
|
||||
eventId = EVENT_MENU_POPUP;
|
||||
else
|
||||
return NS_OK;
|
||||
return PlayEventSound(eventId);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIURI> fileURI;
|
||||
|
||||
// create a nsILocalFile and then a nsIFileURL from that
|
||||
nsCOMPtr <nsILocalFile> soundFile;
|
||||
rv = NS_NewLocalFile(aSoundAlias, PR_TRUE,
|
||||
getter_AddRefs(soundFile));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI,&rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = Play(fileURL);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -39,27 +38,30 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
private:
|
||||
PRBool mInited;
|
||||
|
||||
protected:
|
||||
virtual nsresult Init();
|
||||
virtual void OnShutdown();
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -1,238 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:expandtab:shiftwidth=4:tabstop=4:
|
||||
*/
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <stdint.h>
|
||||
|
||||
static PRLibrary *libcanberra = nsnull;
|
||||
static PRLibrary* libasound = nsnull;
|
||||
|
||||
/* used to find and play common system event sounds.
|
||||
this interfaces with libcanberra.
|
||||
*/
|
||||
typedef struct _ca_context ca_context;
|
||||
|
||||
typedef int (*ca_context_create_fn) (ca_context **);
|
||||
typedef int (*ca_context_destroy_fn) (ca_context *);
|
||||
typedef int (*ca_context_play_fn) (ca_context *c,
|
||||
uint32_t id,
|
||||
...);
|
||||
typedef int (*ca_context_change_props_fn) (ca_context *c,
|
||||
...);
|
||||
|
||||
static ca_context_create_fn ca_context_create;
|
||||
static ca_context_destroy_fn ca_context_destroy;
|
||||
static ca_context_play_fn ca_context_play;
|
||||
static ca_context_change_props_fn ca_context_change_props;
|
||||
|
||||
/* we provide a blank error handler to silence ALSA's stderr
|
||||
messages on computers with no sound devices */
|
||||
typedef void (*snd_lib_error_handler_t) (const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
int err,
|
||||
const char* format,
|
||||
...);
|
||||
typedef int (*snd_lib_error_set_handler_fn) (snd_lib_error_handler_t handler);
|
||||
|
||||
static void
|
||||
quiet_error_handler(const char* file,
|
||||
int line,
|
||||
const char* function,
|
||||
int err,
|
||||
const char* format,
|
||||
...)
|
||||
{
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemSoundService::Init()
|
||||
{
|
||||
PRFuncPtr func =
|
||||
PR_FindFunctionSymbolAndLibrary("snd_lib_error_set_handler",
|
||||
&libasound);
|
||||
if (libasound) {
|
||||
snd_lib_error_set_handler_fn snd_lib_error_set_handler =
|
||||
(snd_lib_error_set_handler_fn) func;
|
||||
snd_lib_error_set_handler(quiet_error_handler);
|
||||
}
|
||||
|
||||
libcanberra = PR_LoadLibrary("libcanberra.so.0");
|
||||
if (libcanberra) {
|
||||
ca_context_create = (ca_context_create_fn)
|
||||
PR_FindFunctionSymbol(libcanberra, "ca_context_create");
|
||||
if (!ca_context_create) {
|
||||
PR_UnloadLibrary(libcanberra);
|
||||
libcanberra = nsnull;
|
||||
} else {
|
||||
// at this point we know we have a good libcanberra library
|
||||
ca_context_destroy = (ca_context_destroy_fn)
|
||||
PR_FindFunctionSymbol(libcanberra, "ca_context_destroy");
|
||||
ca_context_play = (ca_context_play_fn)
|
||||
PR_FindFunctionSymbol(libcanberra, "ca_context_play");
|
||||
ca_context_change_props = (ca_context_change_props_fn)
|
||||
PR_FindFunctionSymbol(libcanberra, "ca_context_change_props");
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemSoundService::OnShutdown()
|
||||
{
|
||||
if (libcanberra) {
|
||||
PR_UnloadLibrary(libcanberra);
|
||||
libcanberra = nsnull;
|
||||
}
|
||||
if (libasound) {
|
||||
PR_UnloadLibrary(libasound);
|
||||
libasound = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
::gdk_beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!libcanberra)
|
||||
return NS_OK;
|
||||
|
||||
// Do we even want alert sounds?
|
||||
// If so, what sound theme are we using?
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
gchar* sound_theme_name = nsnull;
|
||||
|
||||
if (g_object_class_find_property(G_OBJECT_GET_CLASS(settings),
|
||||
"gtk-sound-theme-name") &&
|
||||
g_object_class_find_property(G_OBJECT_GET_CLASS(settings),
|
||||
"gtk-enable-event-sounds")) {
|
||||
gboolean enable_sounds = TRUE;
|
||||
g_object_get(settings, "gtk-enable-event-sounds", &enable_sounds,
|
||||
"gtk-sound-theme-name", &sound_theme_name,
|
||||
NULL);
|
||||
|
||||
if (!enable_sounds) {
|
||||
g_free(sound_theme_name);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// This allows us to avoid race conditions with freeing the context by
|
||||
// handing that responsibility to Glib, and still use one context at a time
|
||||
ca_context* ctx = nsnull;
|
||||
static GStaticPrivate ctx_static_private = G_STATIC_PRIVATE_INIT;
|
||||
ctx = (ca_context*) g_static_private_get(&ctx_static_private);
|
||||
if (!ctx) {
|
||||
ca_context_create(&ctx);
|
||||
if (!ctx) {
|
||||
g_free(sound_theme_name);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
g_static_private_set(&ctx_static_private, ctx,
|
||||
(GDestroyNotify) ca_context_destroy);
|
||||
}
|
||||
|
||||
if (sound_theme_name) {
|
||||
ca_context_change_props(ctx, "canberra.xdg-theme.name",
|
||||
sound_theme_name, NULL);
|
||||
g_free(sound_theme_name);
|
||||
}
|
||||
|
||||
const char* eventID = nsnull;
|
||||
switch (aEventID) {
|
||||
case EVENT_ALERT_DIALOG_OPEN:
|
||||
eventID = "dialog-warning";
|
||||
break;
|
||||
case EVENT_CONFIRM_DIALOG_OPEN:
|
||||
eventID = "dialog-question";
|
||||
break;
|
||||
case EVENT_NEW_MAIL_RECEIVED:
|
||||
eventID = "message-new-email";
|
||||
break;
|
||||
case EVENT_MENU_EXECUTE:
|
||||
eventID = "menu-click";
|
||||
break;
|
||||
case EVENT_MENU_POPUP:
|
||||
eventID = "menu-popup";
|
||||
break;
|
||||
default:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
StopSoundPlayer();
|
||||
ca_context_play(ctx, 0, "event.id", eventID, NULL);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -52,7 +52,6 @@
|
|||
#endif
|
||||
#include "nsFilePicker.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsBidiKeyboard.h"
|
||||
#include "nsNativeKeyBindings.h"
|
||||
#include "nsScreenManagerGtk.h"
|
||||
|
|
@ -101,8 +100,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsClipboard, Init)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerGtk)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageToPixbuf)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAccelerometerUnix)
|
||||
|
|
@ -257,10 +254,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "Accelerometer",
|
||||
NS_ACCELEROMETER_CID,
|
||||
NS_ACCELEROMETER_CONTRACTID,
|
||||
|
|
@ -355,6 +348,7 @@ static void
|
|||
nsWidgetGtk2ModuleDtor(nsIModule *aSelf)
|
||||
{
|
||||
nsFilePicker::Shutdown();
|
||||
nsSound::Shutdown();
|
||||
nsWindow::ReleaseGlobals();
|
||||
nsAppShellShutdown(aSelf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ CPPSRCS = \
|
|||
nsLookAndFeel.cpp \
|
||||
nsOS2Uni.cpp \
|
||||
nsPrintOS2.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
nsToolkit.cpp \
|
||||
nsWidgetFactory.cpp \
|
||||
nsWindow.cpp \
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
* IBM Corp.
|
||||
* Peter Weilbacher <mozilla@Weilbacher.org>
|
||||
* Lars Erdmann
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -57,9 +56,19 @@
|
|||
#include <mcios2.h>
|
||||
#define MCI_ERROR_LENGTH 128
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
static int sInitialized = 0;
|
||||
static PRBool sMMPMInstalled = PR_FALSE;
|
||||
static HMODULE sHModMMIO = NULLHANDLE;
|
||||
|
||||
// function pointer definitions, include underscore (work around redef. warning)
|
||||
|
|
@ -86,27 +95,8 @@ typedef struct _ARGBUFFER
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static void FinalizeGlobals(void)
|
||||
{
|
||||
if (sHModMMIO == NULLHANDLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ULONG ulrc;
|
||||
ulrc = DosFreeModule(sHModMMIO);
|
||||
// do not free MDM.DLL because it doesn't like to be unloaded repeatedly
|
||||
if (ulrc != NO_ERROR) {
|
||||
NS_WARNING("DosFreeModule did not work");
|
||||
}
|
||||
sHModMMIO = NULLHANDLE;
|
||||
}
|
||||
|
||||
static void InitGlobals(void)
|
||||
{
|
||||
if (sHModMMIO != NULLHANDLE) {
|
||||
return;
|
||||
}
|
||||
|
||||
ULONG ulrc = 0;
|
||||
char LoadError[CCHMAXPATH];
|
||||
HMODULE hModMDM = NULLHANDLE;
|
||||
|
|
@ -117,6 +107,7 @@ static void InitGlobals(void)
|
|||
#ifdef DEBUG
|
||||
printf("InitGlobals: MMOS2 is installed, both DLLs loaded\n");
|
||||
#endif
|
||||
sMMPMInstalled = PR_TRUE;
|
||||
// MMOS2 is installed, so we can query the necessary functions
|
||||
// mmio functions are in MMIO.DLL
|
||||
ulrc = DosQueryProcAddr(sHModMMIO, 0L, "mmioOpen", (PFN *)&_mmioOpen);
|
||||
|
|
@ -136,7 +127,7 @@ static void InitGlobals(void)
|
|||
// if one of these failed, we have some kind of non-functional MMOS2 installation
|
||||
if (ulrc != NO_ERROR) {
|
||||
NS_WARNING("MMOS2 is installed, but seems to have corrupt DLLs");
|
||||
FinalizeGlobals();
|
||||
sMMPMInstalled = PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -343,9 +334,6 @@ static void playSound(void *aArgs)
|
|||
break;
|
||||
}
|
||||
|
||||
// stop other sounds
|
||||
nsSystemSoundServiceBase::StopSoundPlayer();
|
||||
|
||||
// play the sound
|
||||
MCI_PLAY_PARMS mpp;
|
||||
memset(&mpp, '\0', sizeof(mpp));
|
||||
|
|
@ -384,56 +372,132 @@ static void playSound(void *aArgs)
|
|||
DosFreeMem(mi.pchBuffer);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
nsSound::nsSound()
|
||||
{
|
||||
if (!sInitialized) {
|
||||
InitGlobals();
|
||||
}
|
||||
sInitialized++;
|
||||
#ifdef DEBUG
|
||||
printf("nsSound::nsSound: sInitialized=%d\n", sInitialized);
|
||||
#endif
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
sInitialized--;
|
||||
#ifdef DEBUG
|
||||
printf("nsSound::~nsSound: sInitialized=%d\n", sInitialized);
|
||||
#endif
|
||||
// (try to) unload modules after last user ended
|
||||
if (!sInitialized) {
|
||||
#ifdef DEBUG
|
||||
printf("nsSound::~nsSound: Trying to free modules...\n");
|
||||
#endif
|
||||
ULONG ulrc;
|
||||
ulrc = DosFreeModule(sHModMMIO);
|
||||
// do not free MDM.DLL because it doesn't like to be unloaded repeatedly
|
||||
if (ulrc != NO_ERROR) {
|
||||
NS_WARNING("DosFreeModule did not work");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemSoundService::Init()
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
InitGlobals();
|
||||
if (NS_FAILED(aStatus)) {
|
||||
#ifdef DEBUG
|
||||
if (aLoader) {
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
aLoader->GetRequest(getter_AddRefs(request));
|
||||
if (request) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
||||
if (channel) {
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
if (uri) {
|
||||
nsCAutoString uriSpec;
|
||||
uri->GetSpec(uriSpec);
|
||||
printf("Failed to load %s\n", uriSpec.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (!sMMPMInstalled) {
|
||||
NS_WARNING("Sound output only works with MMOS2 installed");
|
||||
Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
ARGBUFFER arg;
|
||||
memset(&arg, '\0', sizeof(arg));
|
||||
APIRET rc = DosCreateEventSem(NULL, &(arg.hev), 0UL, 0UL);
|
||||
|
||||
// Play the sound on a new thread using MMOS2, in this case pass
|
||||
// the memory buffer in the argument structure.
|
||||
arg.bufLen = dataLen;
|
||||
arg.buffer = (char *)data;
|
||||
_beginthread(playSound, NULL, 32768, (void *)&arg);
|
||||
|
||||
// Wait until the buffer was copied, but not indefinitely to not block the
|
||||
// UI in case a really large sound file is copied.
|
||||
rc = DosWaitEventSem(arg.hev, 100);
|
||||
rc = DosCloseEventSem(arg.hev);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemSoundService::OnShutdown()
|
||||
NS_IMETHODIMP nsSound::Beep()
|
||||
{
|
||||
FinalizeGlobals();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
WinAlarm(HWND_DESKTOP, WA_WARNING);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayAlias(const nsAString &aSoundAlias)
|
||||
NS_IMETHODIMP nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayAlias(aSoundAlias);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsresult rv;
|
||||
|
||||
if (sHModMMIO == NULLHANDLE) {
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (!sMMPMInstalled) {
|
||||
return Beep();
|
||||
}
|
||||
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
PRUint32 eventId;
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
|
||||
eventId = EVENT_ALERT_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
|
||||
eventId = EVENT_CONFIRM_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
eventId = EVENT_NEW_MAIL_RECEIVED;
|
||||
else
|
||||
return NS_OK;
|
||||
return PlayEventSound(eventId);
|
||||
}
|
||||
nsCAutoString nativeSoundAlias;
|
||||
NS_CopyUnicodeToNative(aSoundAlias, nativeSoundAlias);
|
||||
|
||||
|
|
@ -453,26 +517,20 @@ nsSystemSoundService::PlayAlias(const nsAString &aSoundAlias)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Prompt dialog and select dialog sounds do not correspond to OS/2
|
||||
// system sounds, ignore them. Ignore the menu sounds, too. Try to handle
|
||||
// the rest. Skip the beeps on systems without MMPM, too many of them are
|
||||
// confusing and annoying.
|
||||
switch(aEventID) {
|
||||
switch(aEventId) {
|
||||
case EVENT_NEW_MAIL_RECEIVED:
|
||||
// We don't have a default mail sound on OS/2, so just "beep"
|
||||
return Beep(); // this corresponds to the "Warning" sound
|
||||
case EVENT_ALERT_DIALOG_OPEN:
|
||||
StopSoundPlayer();
|
||||
WinAlarm(HWND_DESKTOP, WA_ERROR); // play "Error" sound
|
||||
break;
|
||||
case EVENT_CONFIRM_DIALOG_OPEN:
|
||||
StopSoundPlayer();
|
||||
WinAlarm(HWND_DESKTOP, WA_NOTE); // play "Information" sound
|
||||
break;
|
||||
}
|
||||
59
widget/src/os2/nsSound.h
Normal file
59
widget/src/os2/nsSound.h
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
|
||||
{
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
};
|
||||
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -71,7 +71,6 @@
|
|||
#include "nsFilePicker.h"
|
||||
#include "nsLookAndFeel.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsToolkit.h"
|
||||
|
||||
// Drag & Drop, Clipboard
|
||||
|
|
@ -101,8 +100,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFrameWindow)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
||||
|
|
@ -154,10 +151,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "OS/2 Toolkit",
|
||||
NS_TOOLKIT_CID,
|
||||
"@mozilla.org/widget/toolkit/os2;1",
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ CPPSRCS = \
|
|||
nsWindow.cpp \
|
||||
nsBidiKeyboard.cpp \
|
||||
nsFilePicker.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
$(NULL)
|
||||
|
||||
# always include the PHOTON_DND in the build - the bookmarks in firefox require it
|
||||
|
|
|
|||
155
widget/src/photon/nsSound.cpp
Normal file
155
widget/src/photon/nsSound.cpp
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
#include "plstr.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include <Pt.h>
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
nsSound::nsSound()
|
||||
{
|
||||
mInited = PR_FALSE;
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult nsSound::Init()
|
||||
{
|
||||
if (mInited) return NS_OK;
|
||||
|
||||
mInited = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Beep()
|
||||
{
|
||||
::PtBeep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsSound::Play");
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "\n\n\nnsSound::Play\n\n" );
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 stringLen,
|
||||
const PRUint8 *stringData)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "\n\n\nnsSound::OnStreamComplete stringData=%s\n\n", stringData );
|
||||
#endif
|
||||
|
||||
if (NS_FAILED(aStatus))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static void child_exit( void *data, int status ) { }
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
NS_ConvertUTF16toUTF8 utf8SoundAlias(aSoundAlias);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf( "\n\n\nnsSound::PlaySystemSound aSoundAlias=%s\n\n",
|
||||
utf8SoundAlias.get() );
|
||||
#endif
|
||||
|
||||
const char *soundfile;
|
||||
|
||||
if( NS_IsMozAliasSound(aSoundAlias) ) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
if ( aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP) )
|
||||
soundfile = "/usr/share/mozilla/gotmail.wav";
|
||||
else
|
||||
return NS_OK;
|
||||
} else {
|
||||
/* the aSoundAlias is the fullpath to the soundfile */
|
||||
if( !access( utf8SoundAlias.get(), F_OK ) )
|
||||
soundfile = utf8SoundAlias.get();
|
||||
else
|
||||
soundfile = "/usr/share/mozilla/rest.wav";
|
||||
}
|
||||
|
||||
const char* argv[] = { "/opt/Mozilla/mozilla/wave", soundfile, NULL };
|
||||
PtSpawn( "/opt/Mozilla/mozilla/wave", ( const char ** ) argv,
|
||||
NULL, NULL, child_exit, NULL, NULL );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
if (aEventId != EVENT_NEW_MAIL_RECEIVED) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
soundfile = "/usr/share/mozilla/gotmail.wav";
|
||||
const char* argv[] = { "/opt/Mozilla/mozilla/wave",
|
||||
"/usr/share/mozilla/gotmail.wav", NULL };
|
||||
PtSpawn( "/opt/Mozilla/mozilla/wave", ( const char ** ) argv,
|
||||
NULL, NULL, child_exit, NULL, NULL );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -36,24 +35,26 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
public:
|
||||
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayAlias(const nsAString &aSoundAlias);
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
private:
|
||||
PRBool mInited;
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
::PtBeep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aEventID != EVENT_NEW_MAIL_RECEIVED) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
StopSoundPlayer();
|
||||
rv = PlayFile(NS_LITERAL_STRING("/usr/share/mozilla/gotmail.wav"));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -54,7 +54,6 @@
|
|||
#include "nsDragService.h"
|
||||
#endif
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#ifdef IBMBIDI
|
||||
#include "nsBidiKeyboard.h"
|
||||
#endif
|
||||
|
|
@ -74,8 +73,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
||||
#endif
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
||||
|
||||
#ifdef IBMBIDI
|
||||
|
|
@ -130,10 +127,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
#ifdef IBMBIDI
|
||||
{ "Gtk Bidi Keyboard",
|
||||
NS_BIDIKEYBOARD_CID,
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ CPPSRCS = \
|
|||
nsDragService.cpp \
|
||||
nsNativeThemeQt.cpp \
|
||||
mozqwidget.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
nsFilePicker.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
|||
412
widget/src/qt/nsSound.cpp
Normal file
412
widget/src/qt/nsSound.cpp
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "plstr.h"
|
||||
#include "prlink.h"
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsIFileURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSound>
|
||||
|
||||
/* used with esd_open_sound */
|
||||
static int esdref = -1;
|
||||
static PRLibrary *elib = nsnull;
|
||||
|
||||
// the following from esd.h
|
||||
|
||||
#define ESD_BITS8 (0x0000)
|
||||
#define ESD_BITS16 (0x0001)
|
||||
#define ESD_MONO (0x0010)
|
||||
#define ESD_STEREO (0x0020)
|
||||
#define ESD_STREAM (0x0000)
|
||||
#define ESD_PLAY (0x1000)
|
||||
|
||||
#define WAV_MIN_LENGTH 44
|
||||
|
||||
typedef int (*EsdOpenSoundType)(const char *host);
|
||||
typedef int (*EsdCloseType)(int);
|
||||
|
||||
/* used to play the sounds from the find symbol call */
|
||||
typedef int (*EsdPlayStreamType) (int, int, const char *, const char *);
|
||||
typedef int (*EsdAudioOpenType) (void);
|
||||
typedef int (*EsdAudioWriteType) (const void *, int);
|
||||
typedef void (*EsdAudioCloseType) (void);
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
nsSound::nsSound()
|
||||
: mInited( PR_FALSE )
|
||||
{
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
/* see above comment */
|
||||
if (esdref != -1) {
|
||||
EsdCloseType EsdClose = (EsdCloseType) PR_FindFunctionSymbol(elib, "esd_close");
|
||||
if (EsdClose)
|
||||
(*EsdClose)(esdref);
|
||||
esdref = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* unload esd library
|
||||
*/
|
||||
void
|
||||
nsSound::Shutdown()
|
||||
{
|
||||
if (elib) {
|
||||
PR_UnloadLibrary(elib);
|
||||
elib = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Init()
|
||||
{
|
||||
/* we don't need to do esd_open_sound if we are only going to play files
|
||||
but we will if we want to do things like streams, etc
|
||||
*/
|
||||
if (mInited)
|
||||
return NS_OK;
|
||||
if (elib)
|
||||
return NS_OK;
|
||||
|
||||
EsdOpenSoundType EsdOpenSound;
|
||||
|
||||
elib = PR_LoadLibrary("libesd.so.0");
|
||||
if (!elib) return NS_ERROR_FAILURE;
|
||||
|
||||
EsdOpenSound = (EsdOpenSoundType) PR_FindFunctionSymbol(elib, "esd_open_sound");
|
||||
|
||||
if (!EsdOpenSound)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
esdref = (*EsdOpenSound)("localhost");
|
||||
|
||||
if (!esdref)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mInited = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Beep()
|
||||
{
|
||||
QApplication::beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This can't be implemented directly with QT.
|
||||
* (We can use QSound to play local files but that was not enough.
|
||||
* Also support of media formats is limited)
|
||||
*
|
||||
* Current implementation is copied from GTK side and implementation uses ESD interface.
|
||||
*
|
||||
* If we have Qtopia then we can drop ESD implementation and use Qtopia "Multimedia API"
|
||||
*/
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
|
||||
#define GET_WORD(s, i) (s[i+1] << 8) | s[i]
|
||||
#define GET_DWORD(s, i) (s[i+3] << 24) | (s[i+2] << 16) | (s[i+1] << 8) | s[i]
|
||||
|
||||
// print a load error on bad status, and return
|
||||
if (NS_FAILED(aStatus)) {
|
||||
#ifdef DEBUG
|
||||
if (aLoader) {
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
aLoader->GetRequest(getter_AddRefs(request));
|
||||
if (request) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
||||
if (channel) {
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
if (uri) {
|
||||
nsCAutoString uriSpec;
|
||||
uri->GetSpec(uriSpec);
|
||||
printf("Failed to load %s\n", uriSpec.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
int fd, mask = 0;
|
||||
PRUint32 samples_per_sec = 0, avg_bytes_per_sec = 0, chunk_len = 0;
|
||||
PRUint16 format, channels = 1, bits_per_sample = 0;
|
||||
const PRUint8 *audio = nsnull;
|
||||
size_t audio_len = 0;
|
||||
|
||||
if (dataLen < 4) {
|
||||
NS_WARNING("Sound stream too short to determine its type");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (memcmp(data, "RIFF", 4)) {
|
||||
#ifdef DEBUG
|
||||
printf("We only support WAV files currently.\n");
|
||||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (dataLen <= WAV_MIN_LENGTH) {
|
||||
NS_WARNING("WAV files should be longer than 44 bytes.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
PRUint32 i = 12;
|
||||
while (i + 7 < dataLen) {
|
||||
if (!memcmp(data + i, "fmt ", 4) && !chunk_len) {
|
||||
i += 4;
|
||||
|
||||
/* length of the rest of this subblock (should be 16 for PCM data */
|
||||
chunk_len = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
if (chunk_len < 16 || i + chunk_len >= dataLen) {
|
||||
NS_WARNING("Invalid WAV file: bad fmt chunk.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
format = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
channels = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
samples_per_sec = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
avg_bytes_per_sec = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
// block align
|
||||
i += 2;
|
||||
|
||||
bits_per_sample = GET_WORD(data, i);
|
||||
i += 2;
|
||||
|
||||
/* we don't support WAVs with odd compression codes */
|
||||
if (chunk_len != 16)
|
||||
NS_WARNING("Extra format bits found in WAV. Ignoring");
|
||||
|
||||
i += chunk_len - 16;
|
||||
} else if (!memcmp(data + i, "data", 4)) {
|
||||
i += 4;
|
||||
if (!chunk_len) {
|
||||
NS_WARNING("Invalid WAV file: no fmt chunk found");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
audio_len = GET_DWORD(data, i);
|
||||
i += 4;
|
||||
|
||||
/* try to play truncated WAVs */
|
||||
if (i + audio_len > dataLen)
|
||||
audio_len = dataLen - i;
|
||||
|
||||
audio = data + i;
|
||||
break;
|
||||
} else {
|
||||
i += 4;
|
||||
i += GET_DWORD(data, i);
|
||||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
if (!audio) {
|
||||
NS_WARNING("Invalid WAV file: no data chunk found");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* No audio data? well, at least the WAV was valid. */
|
||||
if (!audio_len)
|
||||
return NS_OK;
|
||||
|
||||
#if 0
|
||||
printf("f: %d | c: %d | sps: %li | abps: %li | ba: %d | bps: %d | rate: %li\n",
|
||||
format, channels, samples_per_sec, avg_bytes_per_sec, block_align, bits_per_sample, rate);
|
||||
#endif
|
||||
|
||||
/* open up connection to esd */
|
||||
EsdPlayStreamType EsdPlayStream =
|
||||
(EsdPlayStreamType) PR_FindFunctionSymbol(elib,
|
||||
"esd_play_stream");
|
||||
if (!EsdPlayStream)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mask = ESD_PLAY | ESD_STREAM;
|
||||
|
||||
if (bits_per_sample == 8)
|
||||
mask |= ESD_BITS8;
|
||||
else
|
||||
mask |= ESD_BITS16;
|
||||
|
||||
if (channels == 1)
|
||||
mask |= ESD_MONO;
|
||||
else
|
||||
mask |= ESD_STEREO;
|
||||
|
||||
nsAutoArrayPtr<PRUint8> buf;
|
||||
|
||||
// ESD only handle little-endian data.
|
||||
// Swap the byte order if we're on a big-endian architecture.
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
if (bits_per_sample != 8) {
|
||||
buf = new PRUint8[audio_len];
|
||||
if (!buf)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
for (PRUint32 j = 0; j + 2 < audio_len; j += 2) {
|
||||
buf[j] = audio[j + 1];
|
||||
buf[j + 1] = audio[j];
|
||||
}
|
||||
|
||||
audio = buf;
|
||||
}
|
||||
#endif
|
||||
|
||||
fd = (*EsdPlayStream)(mask, samples_per_sec, NULL, "mozillaSound");
|
||||
|
||||
if (fd < 0) {
|
||||
int *esd_audio_format = (int *) PR_FindSymbol(elib, "esd_audio_format");
|
||||
int *esd_audio_rate = (int *) PR_FindSymbol(elib, "esd_audio_rate");
|
||||
EsdAudioOpenType EsdAudioOpen = (EsdAudioOpenType) PR_FindFunctionSymbol(elib, "esd_audio_open");
|
||||
EsdAudioWriteType EsdAudioWrite = (EsdAudioWriteType) PR_FindFunctionSymbol(elib, "esd_audio_write");
|
||||
EsdAudioCloseType EsdAudioClose = (EsdAudioCloseType) PR_FindFunctionSymbol(elib, "esd_audio_close");
|
||||
|
||||
if (!esd_audio_format || !esd_audio_rate ||
|
||||
!EsdAudioOpen || !EsdAudioWrite || !EsdAudioClose)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*esd_audio_format = mask;
|
||||
*esd_audio_rate = samples_per_sec;
|
||||
fd = (*EsdAudioOpen)();
|
||||
|
||||
if (fd < 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
(*EsdAudioWrite)(audio, audio_len);
|
||||
(*EsdAudioClose)();
|
||||
} else {
|
||||
while (audio_len > 0) {
|
||||
size_t written = write(fd, audio, audio_len);
|
||||
if (written <= 0)
|
||||
break;
|
||||
audio += written;
|
||||
audio_len -= written;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (!mInited)
|
||||
Init();
|
||||
|
||||
if (!elib)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (NS_IsMozAliasSound(aSoundAlias)) {
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
return Beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr <nsIURI> fileURI;
|
||||
|
||||
// create a nsILocalFile and then a nsIFileURL from that
|
||||
nsCOMPtr <nsILocalFile> soundFile;
|
||||
rv = NS_NewLocalFile(aSoundAlias, PR_TRUE,
|
||||
getter_AddRefs(soundFile));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI,&rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = Play(fileURL);
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
return aEventId == EVENT_NEW_MAIL_RECEIVED ? Beep() : NS_OK;
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +20,6 @@
|
|||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -36,23 +35,29 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
public:
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
static void Shutdown();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
private:
|
||||
PRBool mInited;
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -1,83 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QSound>
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
QApplication::beep();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aEventID == EVENT_NEW_MAIL_RECEIVED) {
|
||||
StopSoundPlayer();
|
||||
return Beep();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -65,7 +65,6 @@
|
|||
#include "nsIdleServiceQt.h"
|
||||
#include "nsDragService.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsBidiKeyboard.h"
|
||||
#include "nsNativeThemeQt.h"
|
||||
// #include "nsScrollbar.h"
|
||||
|
|
@ -100,8 +99,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService)
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIdleServiceQt)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsSystemSoundService,
|
||||
nsSystemSoundService::GetInstance)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeQt)
|
||||
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker)
|
||||
|
|
@ -171,10 +168,6 @@ static const nsModuleComponentInfo components[] =
|
|||
NS_SOUND_CID,
|
||||
"@mozilla.org/sound;1",
|
||||
nsSoundConstructor },
|
||||
{ "System Sound Service",
|
||||
NS_SYSTEM_SOUND_SERVICE_CID,
|
||||
"@mozilla.org/systemsoundservice;1",
|
||||
nsSystemSoundServiceConstructor },
|
||||
{ "Native Theme Renderer",
|
||||
NS_THEMERENDERER_CID,
|
||||
"@mozilla.org/chrome/chrome-native-theme;1",
|
||||
|
|
@ -189,6 +182,7 @@ static const nsModuleComponentInfo components[] =
|
|||
static void
|
||||
nsWidgetQtModuleDtor(nsIModule *aSelf)
|
||||
{
|
||||
nsSound::Shutdown();
|
||||
nsAppShellShutdown(aSelf);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ CPPSRCS = \
|
|||
nsNativeThemeWin.cpp \
|
||||
nsWinGesture.cpp \
|
||||
nsIdleServiceWin.cpp \
|
||||
nsSystemSoundService.cpp \
|
||||
nsSound.cpp \
|
||||
nsIMM32Handler.cpp \
|
||||
WindowHook.cpp \
|
||||
nsAccelerometerWin.cpp \
|
||||
|
|
|
|||
301
widget/src/windows/nsSound.cpp
Normal file
301
widget/src/windows/nsSound.cpp
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nscore.h"
|
||||
#include "plstr.h"
|
||||
#include <stdio.h>
|
||||
#include "nsString.h"
|
||||
#include <windows.h>
|
||||
|
||||
// mmsystem.h is needed to build with WIN32_LEAN_AND_MEAN
|
||||
#include <mmsystem.h>
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsNativeCharsetUtils.h"
|
||||
|
||||
class nsSoundPlayer: public nsRunnable {
|
||||
public:
|
||||
nsSoundPlayer(nsISound *aSound, const wchar_t* aSoundName) :
|
||||
mSound(aSound), mSoundName(aSoundName)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
nsSoundPlayer(nsISound *aSound, const nsAString& aSoundName) :
|
||||
mSound(aSound), mSoundName(aSoundName)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
protected:
|
||||
nsString mSoundName;
|
||||
nsISound *mSound; // Strong, but this will be released from SoundReleaser.
|
||||
nsCOMPtr<nsIThread> mThread;
|
||||
|
||||
void Init()
|
||||
{
|
||||
NS_GetCurrentThread(getter_AddRefs(mThread));
|
||||
NS_ASSERTION(mThread, "failed to get current thread");
|
||||
NS_IF_ADDREF(mSound);
|
||||
}
|
||||
|
||||
class SoundReleaser: public nsRunnable {
|
||||
public:
|
||||
SoundReleaser(nsISound* aSound) :
|
||||
mSound(aSound)
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
protected:
|
||||
nsISound *mSound;
|
||||
};
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoundPlayer::Run()
|
||||
{
|
||||
NS_PRECONDITION(!mSoundName.IsEmpty(), "Sound name should not be empty");
|
||||
::PlaySoundW(mSoundName.get(), NULL, SND_NODEFAULT | SND_ALIAS | SND_ASYNC);
|
||||
nsCOMPtr<nsIRunnable> releaser = new SoundReleaser(mSound);
|
||||
// Don't release nsISound from here, because here is not an owning thread of
|
||||
// the nsSound. nsSound must be released in its owning thread.
|
||||
mThread->Dispatch(releaser, NS_DISPATCH_NORMAL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSoundPlayer::SoundReleaser::Run()
|
||||
{
|
||||
NS_IF_RELEASE(mSound);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
#ifndef SND_PURGE
|
||||
// Not available on Windows CE, and according to MSDN
|
||||
// doesn't do anything on recent windows either.
|
||||
#define SND_PURGE 0
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsSound, nsISound, nsIStreamLoaderObserver)
|
||||
|
||||
|
||||
nsSound::nsSound()
|
||||
{
|
||||
mLastSound = nsnull;
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
PurgeLastSound();
|
||||
}
|
||||
|
||||
void nsSound::PurgeLastSound() {
|
||||
if (mPlayerThread) {
|
||||
mPlayerThread->Shutdown();
|
||||
mPlayerThread = nsnull;
|
||||
}
|
||||
if (mLastSound) {
|
||||
// Halt any currently playing sound.
|
||||
::PlaySound(nsnull, nsnull, SND_PURGE);
|
||||
|
||||
// Now delete the buffer.
|
||||
free(mLastSound);
|
||||
mLastSound = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::Beep()
|
||||
{
|
||||
::MessageBeep(0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
|
||||
nsISupports *context,
|
||||
nsresult aStatus,
|
||||
PRUint32 dataLen,
|
||||
const PRUint8 *data)
|
||||
{
|
||||
// print a load error on bad status
|
||||
if (NS_FAILED(aStatus)) {
|
||||
#ifdef DEBUG
|
||||
if (aLoader) {
|
||||
nsCOMPtr<nsIRequest> request;
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
aLoader->GetRequest(getter_AddRefs(request));
|
||||
if (request)
|
||||
channel = do_QueryInterface(request);
|
||||
if (channel) {
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
if (uri) {
|
||||
nsCAutoString uriSpec;
|
||||
uri->GetSpec(uriSpec);
|
||||
printf("Failed to load %s\n", uriSpec.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return aStatus;
|
||||
}
|
||||
|
||||
PurgeLastSound();
|
||||
|
||||
if (data && dataLen > 0) {
|
||||
DWORD flags = SND_MEMORY | SND_NODEFAULT;
|
||||
// We try to make a copy so we can play it async.
|
||||
mLastSound = (PRUint8 *) malloc(dataLen);
|
||||
if (mLastSound) {
|
||||
memcpy(mLastSound, data, dataLen);
|
||||
data = mLastSound;
|
||||
flags |= SND_ASYNC;
|
||||
}
|
||||
::PlaySoundW(reinterpret_cast<LPCWSTR>(data), 0, flags);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
#ifdef DEBUG_SOUND
|
||||
char *url;
|
||||
aURL->GetSpec(&url);
|
||||
printf("%s\n", url);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
rv = NS_NewStreamLoader(getter_AddRefs(loader), aURL, this);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsSound::Init()
|
||||
{
|
||||
// This call halts a sound if it was still playing.
|
||||
// We have to use the sound library for something to make sure
|
||||
// it is initialized.
|
||||
// If we wait until the first sound is played, there will
|
||||
// be a time lag as the library gets loaded.
|
||||
::PlaySound(nsnull, nsnull, SND_PURGE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
PurgeLastSound();
|
||||
|
||||
if (!NS_IsMozAliasSound(aSoundAlias)) {
|
||||
if (aSoundAlias.IsEmpty())
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIRunnable> player = new nsSoundPlayer(this, aSoundAlias);
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead");
|
||||
|
||||
PRUint32 eventId;
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP))
|
||||
eventId = EVENT_NEW_MAIL_RECEIVED;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG))
|
||||
eventId = EVENT_CONFIRM_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG))
|
||||
eventId = EVENT_ALERT_DIALOG_OPEN;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_EXECUTE))
|
||||
eventId = EVENT_MENU_EXECUTE;
|
||||
else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP))
|
||||
eventId = EVENT_MENU_POPUP;
|
||||
else
|
||||
return NS_OK;
|
||||
|
||||
return PlayEventSound(eventId);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsSound::PlayEventSound(PRUint32 aEventId)
|
||||
{
|
||||
PurgeLastSound();
|
||||
|
||||
const wchar_t *sound = nsnull;
|
||||
switch (aEventId) {
|
||||
case EVENT_NEW_MAIL_RECEIVED:
|
||||
sound = L"MailBeep";
|
||||
break;
|
||||
case EVENT_ALERT_DIALOG_OPEN:
|
||||
sound = L"SystemExclamation";
|
||||
break;
|
||||
case EVENT_CONFIRM_DIALOG_OPEN:
|
||||
sound = L"SystemQuestion";
|
||||
break;
|
||||
case EVENT_MENU_EXECUTE:
|
||||
sound = L"MenuCommand";
|
||||
break;
|
||||
case EVENT_MENU_POPUP:
|
||||
sound = L"MenuPopup";
|
||||
break;
|
||||
default:
|
||||
// Win32 plays no sounds at NS_SYSSOUND_PROMPT_DIALOG and
|
||||
// NS_SYSSOUND_SELECT_DIALOG.
|
||||
return NS_OK;
|
||||
}
|
||||
NS_ASSERTION(sound, "sound is null");
|
||||
|
||||
nsCOMPtr<nsIRunnable> player = new nsSoundPlayer(this, sound);
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
|
||||
nsresult rv = NS_NewThread(getter_AddRefs(mPlayerThread), player);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
|
|
@ -38,31 +37,31 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsISound.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class nsSound : public nsISound,
|
||||
public nsIStreamLoaderObserver
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayAlias(const nsAString &aSoundAlias);
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
|
||||
protected:
|
||||
virtual nsresult Init();
|
||||
virtual void OnShutdown();
|
||||
NS_DECL_NSISOUND
|
||||
NS_DECL_NSISTREAMLOADEROBSERVER
|
||||
|
||||
private:
|
||||
nsresult PlayNative(const nsAString &aSoundAlias);
|
||||
void PurgeLastSound();
|
||||
|
||||
private:
|
||||
PRUint8* mLastSound;
|
||||
nsCOMPtr<nsIThread> mPlayerThread;
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
#endif /* __nsSound_h__ */
|
||||
|
|
@ -1,208 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsSystemSoundService.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include <windows.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#ifndef SND_PURGE
|
||||
// Not available on Windows CE, and according to MSDN
|
||||
// doesn't do anything on recent windows either.
|
||||
#define SND_PURGE 0
|
||||
#endif
|
||||
|
||||
class nsStopSoundPlayer : public nsRunnable {
|
||||
public:
|
||||
nsStopSoundPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsStopSoundPlayer::Run()
|
||||
{
|
||||
nsSystemSoundServiceBase::StopSoundPlayer();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
class nsSystemSoundPlayer : public nsRunnable {
|
||||
public:
|
||||
nsSystemSoundPlayer(PRUint32 aEventID) :
|
||||
mEventID(aEventID)
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundPlayer(const nsAString &aName) :
|
||||
mEventID(PR_UINT32_MAX), mName(aName)
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
protected:
|
||||
PRUint32 mEventID;
|
||||
nsString mName;
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundPlayer::Run()
|
||||
{
|
||||
const wchar_t *sound = nsnull;
|
||||
if (!mName.IsEmpty()) {
|
||||
sound = static_cast<const wchar_t*>(mName.get());
|
||||
} else if (mEventID != PR_UINT32_MAX) {
|
||||
switch (mEventID) {
|
||||
case nsISystemSoundService::EVENT_NEW_MAIL_RECEIVED:
|
||||
sound = L"MailBeep";
|
||||
break;
|
||||
case nsISystemSoundService::EVENT_ALERT_DIALOG_OPEN:
|
||||
sound = L"SystemExclamation";
|
||||
break;
|
||||
case nsISystemSoundService::EVENT_CONFIRM_DIALOG_OPEN:
|
||||
sound = L"SystemQuestion";
|
||||
break;
|
||||
case nsISystemSoundService::EVENT_MENU_EXECUTE:
|
||||
sound = L"MenuCommand";
|
||||
break;
|
||||
case nsISystemSoundService::EVENT_MENU_POPUP:
|
||||
sound = L"MenuPopup";
|
||||
break;
|
||||
case nsISystemSoundService::EVENT_MENU_NOT_FOUND:
|
||||
// Just beep
|
||||
::MessageBeep(0);
|
||||
return NS_OK;
|
||||
default:
|
||||
// Win32 plays no sounds at NS_SYSSOUND_PROMPT_DIALOG and
|
||||
// NS_SYSSOUND_SELECT_DIALOG.
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if (sound) {
|
||||
nsCOMPtr<nsStopSoundPlayer> stopper = new nsStopSoundPlayer();
|
||||
NS_DispatchToMainThread(stopper, nsIEventTarget::DISPATCH_SYNC);
|
||||
::PlaySoundW(sound, NULL, SND_NODEFAULT | SND_ALIAS | SND_ASYNC);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundService implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundService, nsISystemSoundService)
|
||||
|
||||
NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
nsSystemSoundService::nsSystemSoundService() :
|
||||
nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundService::~nsSystemSoundService()
|
||||
{
|
||||
if (mPlayerThread) {
|
||||
mPlayerThread->Shutdown();
|
||||
mPlayerThread = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemSoundService::Init()
|
||||
{
|
||||
// This call halts a sound if it was still playing.
|
||||
// We have to use the sound library for something to make sure
|
||||
// it is initialized.
|
||||
// If we wait until the first sound is played, there will
|
||||
// be a time lag as the library gets loaded.
|
||||
::PlaySound(nsnull, nsnull, SND_PURGE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::Beep()
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::Beep();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
::MessageBeep(0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayAlias(const nsAString &aSoundAlias)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayAlias(aSoundAlias);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsSystemSoundPlayer> player = new nsSystemSoundPlayer(aSoundAlias);
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
|
||||
return PostPlayer(player);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundService::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
nsresult rv = nsSystemSoundServiceBase::PlayEventSound(aEventID);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsSystemSoundPlayer> player = new nsSystemSoundPlayer(aEventID);
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_OUT_OF_MEMORY);
|
||||
return PostPlayer(player);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemSoundService::PostPlayer(nsSystemSoundPlayer *aPlayer)
|
||||
{
|
||||
nsresult rv;
|
||||
if (mPlayerThread) {
|
||||
rv = mPlayerThread->Dispatch(aPlayer, NS_DISPATCH_NORMAL);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = NS_NewThread(getter_AddRefs(mPlayerThread), aPlayer);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ENSURE_TRUE(mPlayerThread, NS_ERROR_OUT_OF_MEMORY);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2000
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSystemSoundService_h__
|
||||
#define __nsSystemSoundService_h__
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
class nsSystemSoundPlayer;
|
||||
|
||||
class nsSystemSoundService : public nsSystemSoundServiceBase
|
||||
{
|
||||
public:
|
||||
nsSystemSoundService();
|
||||
virtual ~nsSystemSoundService();
|
||||
|
||||
NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(nsSystemSoundService)
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Beep();
|
||||
NS_IMETHOD PlayAlias(const nsAString &aSoundAlias);
|
||||
NS_IMETHOD PlayEventSound(PRUint32 aEventID);
|
||||
|
||||
protected:
|
||||
virtual nsresult Init();
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIThread> mPlayerThread;
|
||||
|
||||
nsresult PostPlayer(nsSystemSoundPlayer *aPlayer);
|
||||
};
|
||||
|
||||
#endif /* __nsSystemSoundService_h__ */
|
||||
|
|
@ -65,7 +65,6 @@ CPPSRCS = \
|
|||
nsIdleService.cpp \
|
||||
nsClipboardPrivacyHandler.cpp \
|
||||
nsAccelerometer.cpp \
|
||||
nsSound.cpp \
|
||||
$(NULL)
|
||||
|
||||
ifneq (,$(filter beos os2 cocoa windows,$(MOZ_WIDGET_TOOLKIT)))
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@
|
|||
#include "nsThreadUtils.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsSound.h"
|
||||
|
||||
// When processing the next thread event, the appshell may process native
|
||||
// events (if not in performance mode), which can result in suppressing the
|
||||
|
|
@ -81,13 +80,6 @@ nsBaseAppShell::Init()
|
|||
do_GetService("@mozilla.org/observer-service;1");
|
||||
if (obsSvc)
|
||||
obsSvc->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
|
||||
|
||||
// The nsISystemSoundService might need to load the system library and it
|
||||
// shouldn't cause the delay of the first sound. So, we need to initialize
|
||||
// the service here, but the actual initializing is going to be run at next
|
||||
// idle time because it shouldn't make the startup process slower.
|
||||
nsSystemSoundServiceBase::InitService();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,333 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsSound.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsITimer.h"
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSound implementation
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSound, nsISound)
|
||||
|
||||
nsSound::nsSound()
|
||||
{
|
||||
}
|
||||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSound::Stop()
|
||||
{
|
||||
nsSystemSoundServiceBase::StopSoundPlayer();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Beep()
|
||||
{
|
||||
nsCOMPtr<nsISystemSoundService> sysSound =
|
||||
nsSystemSoundServiceBase::GetSystemSoundService();
|
||||
NS_ENSURE_TRUE(sysSound, NS_ERROR_FAILURE);
|
||||
return sysSound->Beep();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Init()
|
||||
{
|
||||
// Nothing to do
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
// Stop all sounds before we play a system sound.
|
||||
nsresult rv = Stop();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISystemSoundService> sysSound =
|
||||
nsSystemSoundServiceBase::GetSystemSoundService();
|
||||
NS_ENSURE_TRUE(sysSound, NS_ERROR_FAILURE);
|
||||
return sysSound->PlayEventSound(aEventID);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::Play(nsIURL *aURL)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURL);
|
||||
nsresult rv = nsSystemSoundServiceBase::Play(aURL);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSound::PlaySystemSound(const nsAString &aSoundAlias)
|
||||
{
|
||||
if (aSoundAlias.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
// Stop all sounds before we play a system sound.
|
||||
nsresult rv = Stop();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ASSERTION(!NS_IsMozAliasSound(aSoundAlias),
|
||||
"nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISystemSoundService::playEventSound instead");
|
||||
if (aSoundAlias.Equals(NS_SYSSOUND_MAIL_BEEP)) {
|
||||
rv = PlayEventSound(EVENT_NEW_MAIL_RECEIVED);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_CONFIRM_DIALOG)) {
|
||||
rv = PlayEventSound(EVENT_CONFIRM_DIALOG_OPEN);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_ALERT_DIALOG)) {
|
||||
rv = PlayEventSound(EVENT_ALERT_DIALOG_OPEN);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_PROMPT_DIALOG)) {
|
||||
rv = PlayEventSound(EVENT_PROMPT_DIALOG_OPEN);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_SELECT_DIALOG)) {
|
||||
rv = PlayEventSound(EVENT_SELECT_DIALOG_OPEN);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_EXECUTE)) {
|
||||
rv = PlayEventSound(EVENT_MENU_EXECUTE);
|
||||
} else if (aSoundAlias.Equals(NS_SYSSOUND_MENU_POPUP)) {
|
||||
rv = PlayEventSound(EVENT_MENU_POPUP);
|
||||
} else {
|
||||
// First, assume that the given string is an alias sound name.
|
||||
nsCOMPtr<nsISystemSoundService> sysSound =
|
||||
nsSystemSoundServiceBase::GetSystemSoundService();
|
||||
NS_ENSURE_TRUE(sysSound, NS_ERROR_FAILURE);
|
||||
rv = sysSound->PlayAlias(aSoundAlias);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (rv != NS_SUCCESS_NOT_SUPPORTED) {
|
||||
// The current platform supports the alias sound name, we shouldn't assume
|
||||
// that the given string is a file path.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If this platform doesn't support the alias system sound names, we should
|
||||
// assume that the given string is a file path.
|
||||
nsCOMPtr<nsIFileURL> fileURL =
|
||||
nsSystemSoundServiceBase::GetFileURL(aSoundAlias);
|
||||
if (!fileURL) {
|
||||
return NS_OK;
|
||||
}
|
||||
rv = Play(fileURL);
|
||||
}
|
||||
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* nsSystemSoundServiceBase implementation
|
||||
*****************************************************************************/
|
||||
|
||||
nsISystemSoundService* nsSystemSoundServiceBase::sInstance = nsnull;
|
||||
PRBool nsSystemSoundServiceBase::sIsInitialized = PR_FALSE;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSystemSoundServiceBase, nsISystemSoundService)
|
||||
|
||||
nsSystemSoundServiceBase::nsSystemSoundServiceBase()
|
||||
{
|
||||
}
|
||||
|
||||
nsSystemSoundServiceBase::~nsSystemSoundServiceBase()
|
||||
{
|
||||
if (sInstance == this) {
|
||||
OnShutdown();
|
||||
sInstance = nsnull;
|
||||
sIsInitialized = PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSystemSoundServiceBase::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsSystemSoundServiceBase::OnShutdown()
|
||||
{
|
||||
// Nothing to do.
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsSystemSoundServiceBase::InitService()
|
||||
{
|
||||
nsCOMPtr<nsITimer> timer = do_CreateInstance(NS_TIMER_CONTRACTID);
|
||||
if (!timer) {
|
||||
return; // OOM
|
||||
}
|
||||
NS_ADDREF(timer); // will be released in ExecuteInitService
|
||||
nsresult rv =
|
||||
timer->InitWithFuncCallback(ExecuteInitService, nsnull, 0,
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "nsITimer::InitWithFuncCallback failed");
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsSystemSoundServiceBase::ExecuteInitService(nsITimer* aTimer, void* aClosure)
|
||||
{
|
||||
NS_IF_RELEASE(aTimer);
|
||||
|
||||
// The instance should be created this time.
|
||||
nsCOMPtr<nsISystemSoundService> sysSound =
|
||||
do_GetService("@mozilla.org/systemsoundservice;1");
|
||||
if (!sysSound) {
|
||||
return;
|
||||
}
|
||||
nsresult rv = static_cast<nsSystemSoundServiceBase*>(sysSound.get())->Init();
|
||||
sIsInitialized = NS_SUCCEEDED(rv);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsIFileURL>
|
||||
nsSystemSoundServiceBase::GetFileURL(const nsAString &aFilePath)
|
||||
{
|
||||
if (aFilePath.IsEmpty()) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
rv = NS_NewLocalFile(aFilePath, PR_TRUE, getter_AddRefs(file));
|
||||
if (rv == NS_ERROR_FILE_UNRECOGNIZED_PATH) {
|
||||
return nsnull;
|
||||
}
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
NS_ENSURE_TRUE(file, nsnull);
|
||||
|
||||
PRBool isExists;
|
||||
PRBool isFile;
|
||||
rv = file->Exists(&isExists);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
rv = file->IsFile(&isFile);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
if (!isExists || !isFile) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> fileURI;
|
||||
rv = NS_NewFileURI(getter_AddRefs(fileURI), file);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(fileURI, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
// The file URL must not be null here because the given string is a native
|
||||
// file path of an existing file.
|
||||
NS_ENSURE_TRUE(fileURI, nsnull);
|
||||
|
||||
return fileURL.forget();
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsISystemSoundService>
|
||||
nsSystemSoundServiceBase::GetSystemSoundService()
|
||||
{
|
||||
NS_ENSURE_TRUE(sInstance, nsnull);
|
||||
NS_ADDREF(sInstance);
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsISoundPlayer>
|
||||
nsSystemSoundServiceBase::GetSoundPlayer()
|
||||
{
|
||||
nsCOMPtr<nsISoundPlayer> player =
|
||||
do_GetService("@mozilla.org/content/media/soundplayer;1");
|
||||
NS_ENSURE_TRUE(player, nsnull);
|
||||
return player.forget();
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsSystemSoundServiceBase::PlayFile(const nsAString &aFilePath)
|
||||
{
|
||||
nsCOMPtr<nsIFileURL> fileURL = GetFileURL(aFilePath);
|
||||
if (!fileURL) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISoundPlayer> player = GetSoundPlayer();
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_FAILURE);
|
||||
|
||||
return player->Play(fileURL);
|
||||
}
|
||||
|
||||
/* static */ nsresult
|
||||
nsSystemSoundServiceBase::Play(nsIURL *aURL)
|
||||
{
|
||||
nsCOMPtr<nsISoundPlayer> player = GetSoundPlayer();
|
||||
NS_ENSURE_TRUE(player, NS_ERROR_FAILURE);
|
||||
|
||||
// We don't need to stop the previous sound before we play a new sound.
|
||||
return player->Play(aURL);
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
nsSystemSoundServiceBase::StopSoundPlayer()
|
||||
{
|
||||
nsCOMPtr<nsISoundPlayer> player = GetSoundPlayer();
|
||||
if (player) {
|
||||
player->Stop();
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundServiceBase::Beep()
|
||||
{
|
||||
NS_ENSURE_TRUE(sIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||
return NS_SUCCESS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundServiceBase::PlayAlias(const nsAString &aSoundAlias)
|
||||
{
|
||||
NS_ENSURE_TRUE(sIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||
return NS_SUCCESS_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSystemSoundServiceBase::PlayEventSound(PRUint32 aEventID)
|
||||
{
|
||||
NS_ENSURE_TRUE(sIsInitialized, NS_ERROR_NOT_INITIALIZED);
|
||||
return NS_SUCCESS_NOT_SUPPORTED;
|
||||
}
|
||||
|
|
@ -1,123 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Mozilla Japan.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2009
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Masayuki Nakano <masayuki@d-toybox.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsSound_h__
|
||||
#define __nsSound_h__
|
||||
|
||||
#include "nsISound.h"
|
||||
#include "nsISystemSoundService.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISoundPlayer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIFileURL.h"
|
||||
|
||||
class nsITimer;
|
||||
|
||||
class nsSound : public nsISound
|
||||
{
|
||||
public:
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
|
||||
protected:
|
||||
nsresult Stop();
|
||||
};
|
||||
|
||||
// Playing system sound methods of nsSystemSoundServiceBase return this code if
|
||||
// the platform doesn't support the method. So, they never return
|
||||
// NS_ERROR_NOT_IMPLEMENTED.
|
||||
#define NS_SUCCESS_NOT_SUPPORTED \
|
||||
NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_GENERAL, 1)
|
||||
|
||||
// The implementation class of nsISystemSoundService should be singleton.
|
||||
// These macros declares/implements the GetInstance method.
|
||||
#define NS_DECL_ISYSTEMSOUNDSERVICE_GETINSTANCE(_InstanceClass) \
|
||||
static _InstanceClass* GetInstance();
|
||||
|
||||
#define NS_IMPL_ISYSTEMSOUNDSERVICE_GETINSTANCE(_InstanceClass) \
|
||||
_InstanceClass* \
|
||||
_InstanceClass::GetInstance() \
|
||||
{ \
|
||||
if (sInstance) { \
|
||||
NS_ADDREF(sInstance); \
|
||||
return static_cast<_InstanceClass*>(sInstance); \
|
||||
} \
|
||||
\
|
||||
sInstance = new _InstanceClass(); \
|
||||
NS_ENSURE_TRUE(sInstance, nsnull); \
|
||||
NS_ADDREF(sInstance); \
|
||||
return static_cast<_InstanceClass*>(sInstance); \
|
||||
}
|
||||
|
||||
// Base class of each platform-specific nsSystemSoundService.
|
||||
class nsSystemSoundServiceBase : public nsISystemSoundService
|
||||
{
|
||||
public:
|
||||
nsSystemSoundServiceBase();
|
||||
virtual ~nsSystemSoundServiceBase();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISYSTEMSOUNDSERVICE
|
||||
|
||||
static void InitService();
|
||||
static already_AddRefed<nsIFileURL> GetFileURL(const nsAString &aFilePath);
|
||||
static already_AddRefed<nsISystemSoundService> GetSystemSoundService();
|
||||
static already_AddRefed<nsISoundPlayer> GetSoundPlayer();
|
||||
static nsresult PlayFile(const nsAString &aFilePath);
|
||||
static nsresult Play(nsIURL *aURL);
|
||||
// Stops playing all in-progress sounds that are played via nsISoundPlayer.
|
||||
// This method should be called by the inherited class before it plays a
|
||||
// system sound by PlayAlias() and PlayEventSound().
|
||||
static void StopSoundPlayer();
|
||||
|
||||
protected:
|
||||
static nsISystemSoundService* sInstance;
|
||||
static PRBool sIsInitialized;
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual void OnShutdown();
|
||||
|
||||
private:
|
||||
static void ExecuteInitService(nsITimer* aTimer, void* aClosure);
|
||||
};
|
||||
|
||||
#endif /* __nsSound_h__ */
|
||||
Loading…
Reference in a new issue