web-audio-api-player
Advanced tools
Comparing version 2.0.3 to 3.0.0
@@ -1,2 +0,2 @@ | ||
import { typeSoundModes } from './core'; | ||
import { typePlayerModes } from './core'; | ||
import { ISound } from './sound'; | ||
@@ -26,3 +26,3 @@ interface IAudioGraph { | ||
persistVolume: boolean; | ||
loadSoundMode: typeSoundModes; | ||
loadPlayerMode: typePlayerModes; | ||
} | ||
@@ -51,3 +51,3 @@ interface IAudioBufferSourceOptions extends AudioBufferSourceOptions { | ||
protected _persistVolume: boolean; | ||
protected _loadSoundMode: typeSoundModes; | ||
protected _loadPlayerMode: typePlayerModes; | ||
constructor(options: IAudioOptions); | ||
@@ -77,5 +77,5 @@ decodeAudio(arrayBuffer: ArrayBuffer): Promise<AudioBuffer>; | ||
getPersistVolume(): boolean; | ||
setLoadSoundMode(loadSoundMode: typeSoundModes): void; | ||
getLoadSoundMode(): typeSoundModes; | ||
setLoadPlayerMode(loadPlayerMode: typePlayerModes): void; | ||
getLoadPlayerMode(): typePlayerModes; | ||
} | ||
export { PlayerAudio, IAudioGraph, IAudioOptions, IAudioBufferSourceOptions, IMediaElementAudioSourceOptions, IMediaElementAudioSourceNode }; |
@@ -1,8 +0,8 @@ | ||
import { ISound, ISoundAttributes, ISoundSource } from './sound'; | ||
import { ISound, ISoundAttributes, ISoundSource, typeSoundStates } from './sound'; | ||
import { PlayerAudio, IAudioGraph, IAudioOptions } from './audio'; | ||
import { PlayerError } from './error'; | ||
declare const SOUND_MODE_AUDIO = "sound_mode_audio"; | ||
declare const SOUND_MODE_AJAX = "sound_mode_ajax"; | ||
declare const SOUND_MODE_FETCH = "sound_mode_fetch"; | ||
export declare type typeSoundModes = typeof SOUND_MODE_AUDIO | typeof SOUND_MODE_AJAX | typeof SOUND_MODE_FETCH; | ||
declare const PLAYER_MODE_AUDIO = "player_mode_audio"; | ||
declare const PLAYER_MODE_AJAX = "player_mode_ajax"; | ||
declare const PLAYER_MODE_FETCH = "player_mode_fetch"; | ||
export declare type typePlayerModes = typeof PLAYER_MODE_AUDIO | typeof PLAYER_MODE_AJAX | typeof PLAYER_MODE_FETCH; | ||
export interface ICoreOptions { | ||
@@ -21,3 +21,3 @@ volume?: number; | ||
persistVolume?: boolean; | ||
loadSoundMode?: typeSoundModes; | ||
loadPlayerMode?: typePlayerModes; | ||
} | ||
@@ -66,3 +66,3 @@ interface ISoundsQueueOptions { | ||
protected _persistVolume: boolean; | ||
protected _loadSoundMode: typeSoundModes; | ||
protected _loadPlayerMode: typePlayerModes; | ||
static readonly WHERE_IN_QUEUE_AT_END: string; | ||
@@ -75,5 +75,5 @@ static readonly WHERE_IN_QUEUE_AT_START: string; | ||
static readonly PLAY_SOUND_LAST = "last"; | ||
static readonly SOUND_MODE_AUDIO = "sound_mode_audio"; | ||
static readonly SOUND_MODE_AJAX = "sound_mode_ajax"; | ||
static readonly SOUND_MODE_FETCH = "sound_mode_fetch"; | ||
static readonly PLAYER_MODE_AUDIO = "player_mode_audio"; | ||
static readonly PLAYER_MODE_AJAX = "player_mode_ajax"; | ||
static readonly PLAYER_MODE_FETCH = "player_mode_fetch"; | ||
constructor(playerOptions?: ICoreOptions); | ||
@@ -121,3 +121,3 @@ protected _initialize(): void; | ||
stop(): void; | ||
protected _stop(sound: ISound): void; | ||
protected _stop(sound: ISound, soundState: typeSoundStates): void; | ||
next(): void; | ||
@@ -124,0 +124,0 @@ previous(): void; |
@@ -0,1 +1,5 @@ | ||
declare const SOUND_STATE_STOPPED = "sound_state_stopped"; | ||
declare const SOUND_STATE_PAUSED = "sound_state_paused"; | ||
declare const SOUND_STATE_PLAYING = "sound_state_playing"; | ||
export declare type typeSoundStates = typeof SOUND_STATE_STOPPED | typeof SOUND_STATE_PAUSED | typeof SOUND_STATE_PLAYING; | ||
export interface ISoundSource { | ||
@@ -44,3 +48,3 @@ url: string; | ||
playedTimePercentage: number; | ||
isPlaying: boolean; | ||
state: typeSoundStates; | ||
source: (ISoundSource)[] | ISoundSource; | ||
@@ -56,2 +60,5 @@ url: string | null; | ||
export declare class PlayerSound implements ISound { | ||
static readonly SOUND_STATE_STOPPED = "sound_state_stopped"; | ||
static readonly SOUND_STATE_PAUSED = "sound_state_paused"; | ||
static readonly SOUND_STATE_PLAYING = "sound_state_playing"; | ||
source: (ISoundSource)[] | ISoundSource; | ||
@@ -75,3 +82,3 @@ url: string | null; | ||
playedTimePercentage: number; | ||
isPlaying: boolean; | ||
state: typeSoundStates; | ||
loadingProgress: number; | ||
@@ -91,1 +98,2 @@ duration: number | null; | ||
} | ||
export {}; |
{ | ||
"name": "web-audio-api-player", | ||
"version": "2.0.3", | ||
"version": "3.0.0", | ||
"description": "web audio api player", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -30,5 +30,5 @@ [![Dependencies](https://david-dm.org/chrisweb/web-audio-api-player/status.svg)](https://david-dm.org/chrisweb/web-audio-api-player) | ||
This player has two modes, SOUND_MODE_AUDIO which uses the audio element to load sounds via the audio element and SOUND_MODE_FETCH to load sounds via the web audio API. Here are some of the differences between the two: | ||
This player has two modes, PLAYER_MODE_AUDIO which uses the audio element to load sounds via the audio element and PLAYER_MODE_FETCH to load sounds via the web audio API. Here are some of the differences between the two: | ||
### the web audio API (SOUND_MODE_FETCH) | ||
### the web audio API (PLAYER_MODE_FETCH) | ||
@@ -41,3 +41,3 @@ * No support for streaming | ||
### the audio element (SOUND_MODE_AUDIO) | ||
### the audio element (PLAYER_MODE_AUDIO) | ||
@@ -54,11 +54,11 @@ * Support for streaming | ||
If you use this library, the difference is only how the sound (song) gets loaded (see list of differences above). If using fetch the source is a Buffer and if using the "HTML audio element" well the source is a media element. Everything that happens after is the same. This is why you can change in the player options the SOUND_MODE, to either load the sound using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) or load / stream it using the [audio element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio). But this influences only how the sound get loaded (fetched), if loaded via audio element, we use the web audio API [createMediaElementSource method](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource) of the audiocontext to pass it to the audiocontext of the web audio API. After feeding the web audio API with the input from the web audio element, the playback and what you do with it is being handled by the web audio API. | ||
If you use this library, the difference is only how the sound (song) gets loaded (see list of differences above). If using fetch the source is a Buffer and if using the "HTML audio element" well the source is a media element. Everything that happens after is the same. This is why you can change in the player options the PLAYER_MODE, to either load the sound using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) or load / stream it using the [audio element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio). But this influences only how the sound get loaded (fetched), if loaded via audio element, we use the web audio API [createMediaElementSource method](https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createMediaElementSource) of the audiocontext to pass it to the audiocontext of the web audio API. After feeding the web audio API with the input from the web audio element, the playback and what you do with it is being handled by the web audio API. | ||
### so which SOUND_MODE should I use | ||
### so which PLAYER_MODE should I use | ||
It depends on what you intend to build. | ||
If you build a game where you have a lot (of small sounds) that get (pre-)loaded and maybe cached but played later at some time after they finished loading, use SOUND_MODE_FETCH. It's progress is easier to understand, because when the loading progress of the sound has reached 100% you know it can be played. To display the loading progress a simple [HTML progress element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) is enough. | ||
If you build a game where you have a lot (of small sounds) that get (pre-)loaded and maybe cached but played later at some time after they finished loading, use PLAYER_MODE_FETCH. It's progress is easier to understand, because when the loading progress of the sound has reached 100% you know it can be played. To display the loading progress a simple [HTML progress element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress) is enough. | ||
If you build a music player, use the SOUND_MODE_AUDIO as you might to want to start playing the sound (song) as quickly as possible and don't care if it has fully loaded yet as long as the part that has been loaded is enough to play the song until the end (while the rest of it is being streamed from the server in the background). To display the time range(s) that have been loaded you could for example use a [2D canvas element](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D). | ||
If you build a music player, use the PLAYER_MODE_AUDIO as you might to want to start playing the sound (song) as quickly as possible and don't care if it has fully loaded yet as long as the part that has been loaded is enough to play the song until the end (while the rest of it is being streamed from the server in the background). To display the time range(s) that have been loaded you could for example use a [2D canvas element](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D). | ||
@@ -65,0 +65,0 @@ ### advanced usage |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
185511
3426