michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsSound.h" michael@0: #include "nsObjCExceptions.h" michael@0: #include "nsNetUtil.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIURL.h" michael@0: #include "nsString.h" michael@0: michael@0: #import michael@0: michael@0: NS_IMPL_ISUPPORTS(nsSound, nsISound, nsIStreamLoaderObserver) michael@0: michael@0: nsSound::nsSound() michael@0: { michael@0: } michael@0: michael@0: nsSound::~nsSound() michael@0: { michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::Beep() michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: NSBeep(); michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::OnStreamComplete(nsIStreamLoader *aLoader, michael@0: nsISupports *context, michael@0: nsresult aStatus, michael@0: uint32_t dataLen, michael@0: const uint8_t *data) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: NSData *value = [NSData dataWithBytes:data length:dataLen]; michael@0: michael@0: NSSound *sound = [[NSSound alloc] initWithData:value]; michael@0: michael@0: [sound play]; michael@0: michael@0: [sound autorelease]; michael@0: michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::Play(nsIURL *aURL) michael@0: { michael@0: nsCOMPtr uri(do_QueryInterface(aURL)); michael@0: nsCOMPtr loader; michael@0: return NS_NewStreamLoader(getter_AddRefs(loader), uri, this); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::Init() michael@0: { michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::PlaySystemSound(const nsAString &aSoundAlias) michael@0: { michael@0: NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT; michael@0: michael@0: if (NS_IsMozAliasSound(aSoundAlias)) { michael@0: NS_WARNING("nsISound::playSystemSound is called with \"_moz_\" events, they are obsolete, use nsISound::playEventSound instead"); michael@0: // Mac doesn't have system sound settings for each user actions. michael@0: return NS_OK; michael@0: } michael@0: michael@0: NSString *name = [NSString stringWithCharacters:reinterpret_cast(aSoundAlias.BeginReading()) michael@0: length:aSoundAlias.Length()]; michael@0: NSSound *sound = [NSSound soundNamed:name]; michael@0: if (sound) { michael@0: [sound stop]; michael@0: [sound play]; michael@0: } michael@0: michael@0: return NS_OK; michael@0: michael@0: NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsSound::PlayEventSound(uint32_t aEventId) michael@0: { michael@0: // Mac doesn't have system sound settings for each user actions. michael@0: return NS_OK; michael@0: }