179138 patch by mloiselle@yahoo.com r=pavlov sr=blizzard nsSound::Play doesn't

git-svn-id: svn://10.0.0.236/trunk@143453 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
cbiesinger%web.de
2003-06-09 16:04:23 +00:00
parent 0a3e5f606c
commit f1e63b719a

View File

@@ -28,6 +28,7 @@
#include "nsSound.h"
#include "nsIURL.h"
#include "nsIFileURL.h"
#include "nsNetUtil.h"
#include "nsCOMPtr.h"
@@ -103,8 +104,8 @@ nsSound::Init()
return NS_OK;
}
#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]
#define GET_WORD(s, i) ((unsigned char)s[i+1] << 8) | (unsigned char)s[i]
#define GET_DWORD(s, i) ((unsigned char)s[i+3] << 24) | ((unsigned char)s[i+2] << 16) | ((unsigned char)s[i+1] << 8) | (unsigned char)s[i]
NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
nsISupports *context,
@@ -137,9 +138,9 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
int fd, mask = 0;
long samples_per_sec, avg_bytes_per_sec;
long rate;
int format, channels = 1, block_align, bits_per_sample;
unsigned long samples_per_sec=0, avg_bytes_per_sec=0;
unsigned long rate=0;
unsigned short format, channels = 1, block_align, bits_per_sample=0;
if (PL_strncmp(string, "RIFF", 4)) {
@@ -181,13 +182,13 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
bits_per_sample = GET_WORD(string, i);
i+=2;
rate = samples_per_sec * channels * (bits_per_sample / 8);
rate = samples_per_sec;
break;
}
}
#if 0
#ifdef DEBUG
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
@@ -223,7 +224,7 @@ NS_IMETHODIMP nsSound::OnStreamComplete(nsIStreamLoader *aLoader,
NS_METHOD nsSound::Beep()
{
::gdk_beep();
::gdk_beep();
return NS_OK;
}
@@ -245,5 +246,25 @@ NS_METHOD nsSound::Play(nsIURL *aURL)
NS_IMETHODIMP nsSound::PlaySystemSound(const char *aSoundAlias)
{
return Beep();
if (!aSoundAlias) return NS_ERROR_FAILURE;
if (strcmp(aSoundAlias, "_moz_mailbeep") == 0)
{
return Beep();
}
nsresult rv;
nsCOMPtr <nsIURI> fileURI;
// create a nsILocalFile and then a nsIFileURL from that
nsCOMPtr <nsILocalFile> soundFile;
rv = NS_NewNativeLocalFile(nsDependentCString(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;
}