зеркало из https://github.com/mozilla/pjs.git
Convert nsISound to use URIs. On windows (Linux to follow) nsSound uses necko to read the URI data
into a buffer, and then sends it to win32 PlaySound to play asynchronously. r=nisheeth r=hyatt.
This commit is contained in:
Родитель
c740ffbda3
Коммит
04e0368758
|
@ -21,14 +21,14 @@
|
|||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIFileSpec.idl"
|
||||
#include "nsIURI.idl"
|
||||
|
||||
[scriptable, uuid(B148EED1-236D-11d3-B35C-00A0CC3C1CDE)]
|
||||
interface nsISound : nsISupports
|
||||
{
|
||||
void Init();
|
||||
|
||||
void Play(in nsIFileSpec filespec);
|
||||
void Play(in nsIURI aURI);
|
||||
// void Stop();
|
||||
|
||||
void Beep();
|
||||
|
|
|
@ -75,8 +75,9 @@ NS_METHOD nsSound::Beep()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
||||
NS_METHOD nsSound::Play(nsIURI *aURI)
|
||||
{
|
||||
/*
|
||||
char *filename;
|
||||
filespec->GetNativePath(&filename);
|
||||
|
||||
|
@ -89,6 +90,6 @@ NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
|||
mSound->StartPlaying();
|
||||
|
||||
nsCRT::free(filename);
|
||||
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -106,8 +106,9 @@ NS_METHOD nsSound::Beep()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
||||
NS_METHOD nsSound::Play(nsIURI *aURI)
|
||||
{
|
||||
/*
|
||||
if (lib)
|
||||
{
|
||||
char *filename;
|
||||
|
@ -121,5 +122,6 @@ NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
|||
|
||||
return NS_OK;
|
||||
}
|
||||
*/
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,10 @@ class nsSound : public nsISound {
|
|||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
NS_IMETHOD Play(nsIURI *aURI);
|
||||
NS_IMETHOD Init(void);
|
||||
NS_IMETHOD Beep(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ NS_METHOD nsSound::Beep()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
||||
NS_METHOD nsSound::Play(nsIURI *aURI)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("nsSound::Play");
|
||||
return NS_OK;
|
||||
|
|
|
@ -23,11 +23,14 @@
|
|||
#include "nscore.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "plstr.h"
|
||||
#include "stdio.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "nsSound.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "prmem.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsSound, nsCOMTypeInfo<nsISound>::GetIID());
|
||||
|
||||
|
@ -39,6 +42,10 @@ nsSound::nsSound()
|
|||
|
||||
nsSound::~nsSound()
|
||||
{
|
||||
if (mPlayBuf)
|
||||
PR_Free( mPlayBuf );
|
||||
if (mBuffer)
|
||||
PR_Free( mBuffer );
|
||||
}
|
||||
|
||||
nsresult NS_NewSound(nsISound** aSound)
|
||||
|
@ -46,11 +53,18 @@ nsresult NS_NewSound(nsISound** aSound)
|
|||
NS_PRECONDITION(aSound != nsnull, "null ptr");
|
||||
if (! aSound)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsSound** mySound;
|
||||
|
||||
*aSound = new nsSound();
|
||||
if (! *aSound)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
mySound = (nsSound **) aSound;
|
||||
(*mySound)->mBufferSize = 4098;
|
||||
(*mySound)->mBuffer = (char *) PR_Malloc( (*mySound)->mBufferSize );
|
||||
if ( (*mySound)->mBuffer == (char *) NULL )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
(*mySound)->mPlayBuf = (char *) NULL;
|
||||
NS_ADDREF(*aSound);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -69,15 +83,46 @@ NS_METHOD nsSound::Beep()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsSound::Play(nsIFileSpec *filespec)
|
||||
NS_METHOD nsSound::Play(nsIURI *aURI)
|
||||
{
|
||||
char *filename;
|
||||
filespec->GetNativePath(&filename);
|
||||
|
||||
::PlaySound(filename, nsnull, SND_FILENAME | SND_NODEFAULT | SND_ASYNC);
|
||||
|
||||
nsCRT::free(filename);
|
||||
|
||||
nsresult rv;
|
||||
nsIInputStream *inputStream;
|
||||
PRUint32 totalLen = 0;
|
||||
PRUint32 len;
|
||||
|
||||
if ( mPlayBuf ) {
|
||||
::PlaySound(nsnull, nsnull, 0); // stop what might be playing so we can free
|
||||
PR_Free( this->mPlayBuf );
|
||||
this->mPlayBuf = (char *) NULL;
|
||||
}
|
||||
rv = NS_OpenURI(&inputStream, aURI);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
do {
|
||||
rv = inputStream->Read(this->mBuffer, this->mBufferSize, &len);
|
||||
if ( len ) {
|
||||
totalLen += len;
|
||||
if ( this->mPlayBuf == (char *) NULL ) {
|
||||
this->mPlayBuf = (char *) PR_Malloc( len );
|
||||
if ( this->mPlayBuf == (char *) NULL ) {
|
||||
NS_IF_RELEASE( inputStream );
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy( this->mPlayBuf, this->mBuffer, len );
|
||||
}
|
||||
else {
|
||||
this->mPlayBuf = (char *) PR_Realloc( this->mPlayBuf, totalLen );
|
||||
if ( this->mPlayBuf == (char *) NULL ) {
|
||||
NS_IF_RELEASE( inputStream );
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy( this->mPlayBuf + (totalLen - len), this->mBuffer, len );
|
||||
}
|
||||
}
|
||||
} while (len > 0);
|
||||
if ( this->mPlayBuf != (char *) NULL )
|
||||
::PlaySound(this->mPlayBuf, nsnull, SND_MEMORY | SND_NODEFAULT | SND_ASYNC);
|
||||
NS_IF_RELEASE( inputStream );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,9 @@ class nsSound : public nsISound {
|
|||
|
||||
nsSound();
|
||||
virtual ~nsSound();
|
||||
|
||||
char *mPlayBuf;
|
||||
char *mBuffer;
|
||||
PRInt32 mBufferSize;
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISOUND
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче