core/audioplayer
오디오 플레이어.
Audio player.
AudioPlayer
오디오 플레이어. AudioAsset 에 로드된 오디오 버퍼를 재생한다. 내보낼 노드를 주면(AudioBus.createAudioPlayer) 출력 대신 그 노드로 소리를 낸다. 스트리밍 애셋(AudioLoadType.streaming)은 플레이어마다 미디어 요소 하나를 MediaElementAudioSourceNode 로 같은 GainNode 에 이어 튼다.
- 재생, 멈춤, 반복, 음량, 음소거, 빠르기, 위치, 끝(isPlaying 이 거짓이 됨)이 통째로 푼 애셋과 같다.
- 오디오 컨텍스트가 멈추면(suspend, 탭이 숨음, 음소거) 미디어 요소도 멈추고, 다시 돌면 이어 튼다. (버퍼 소리가 컨텍스트 시계와 같이 멈추는 것과 같게)
Audio player. Plays the audio buffer loaded into an AudioAsset. If an output node is given (AudioBus.createAudioPlayer), sound goes to that node instead of the output. A streaming asset (AudioLoadType.streaming) is played by one media element per player, connected to the same GainNode with a MediaElementAudioSourceNode.
- Play, stop, loop, volume, mute, rate, position and end (isPlaying turns false) behave the same as a fully decompressed asset.
- When the audio context stops (suspend, hidden tab, mute) the media element also pauses, and resumes when it runs again. (the same as buffer sounds stopping with the context clock)
import { Engine, EngineConfiguration, AudioAsset } from "./build/vanilla.js";
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const audioManager = engine.getAudioManager();
const audioAsset = new AudioAsset();
await audioAsset.load("examples/assets/beep.wav");
const audioPlayer = audioManager.createAudioPlayer();
audioPlayer.setAudioAsset(audioAsset);
audioPlayer.setVolume(0.8);
audioPlayer.setPlaybackRate(1.5);
audioPlayer.play(false);
console.log(audioPlayer.getDuration(), audioPlayer.getVolume());생성.
Constructor.
- audioContextAudioContext | null
- 재생에 쓸 오디오 컨텍스트. (null 이면 소리를 내지 않는 플레이어)Audio context used for playback. (if null, a player that makes no sound)
- outputNodeAudioNode | null
- 소리를 내보낼 노드. (null 이면 audioContext.destination)Node to send sound to. (audioContext.destination if null)
짝Counterpart: vanilla-engine AudioPlayer.new
재생.
Play.
- loopboolean
- 반복 재생하면 참. (기본 거짓)True if it loops. (default false)
짝Counterpart: vanilla-engine AudioPlayer.play
내부 재생 시작.
Starts internal playback.
- audioBufferAudioBuffer
- 재생할 오디오 버퍼.Audio buffer to play.
- loopboolean
- 반복 재생하면 참.True to loop.
재생 빠르기 설정. (1 이면 그대로, 음 높이도 같이 바뀐다, 다음 play 부터, 0 이하이거나 숫자가 아니면 1)
Sets the playback rate. (1 is unchanged, pitch changes too, from the next play, 1 if 0 or less or not a number)
- playbackRatenumber
- 재생 빠르기. (1 이면 그대로)Playback rate. (1 is unchanged)
짝Counterpart: vanilla-engine AudioPlayer.set_playback_rate
음소거 해제. (설정한 음량으로 돌아간다)
Unmute. (returns to the set volume)
짝Counterpart: vanilla-engine AudioPlayer.unmute
음량 설정. (0 ~ 1, 음소거 중이면 음소거를 풀 때 적용된다)
Sets the volume. (0 ~ 1, if muted it applies when unmuted)
- volumenumber
- 음량. (0 ~ 1 로 자르고, 유한한 숫자가 아니면 1)Volume. (clamped to 0 ~ 1, 1 if not a finite number)
짝Counterpart: vanilla-engine AudioPlayer.set_volume
음량 반환.
Returns the volume.
반환Returnsnumber 음량. (0 ~ 1, 기본 1)Volume. (0 ~ 1, default 1)
짝Counterpart: vanilla-engine AudioPlayer.get_volume
재생 위치 설정. 재생 중이면 해당 위치부터 즉시 다시 재생.
Sets the playback position. If playing, immediately replays from that position.
- timenumber
- 재생 위치 (초).Playback position (seconds).
짝Counterpart: vanilla-engine AudioPlayer.set_time
오디오 애셋 설정.
Sets the audio asset.
- audioAssetAudioAsset | null
- 재생할 오디오 애셋. (다음 play 부터, 스트리밍으로 틀던 것이 멈춰 있으면 그 미디어 요소가 받아 둔 것을 놓는다)The audio asset to play. (from the next play, if a streaming sound was playing and is stopped, its media element releases what it had loaded)
짝Counterpart: vanilla-engine AudioPlayer.set_audio_asset
오디오 애셋 반환.
Returns the audio asset.
반환ReturnsAudioAsset | null 오디오 애셋. (없으면 null)Audio asset. (null if none)
짝Counterpart: vanilla-engine AudioPlayer.get_audio_asset
재생 여부 반환.
Returns whether playing.
반환Returnsboolean 재생 중이면 참. (끝까지 재생되면 거짓이 된다)True if playing. (becomes false when it plays to the end)
짝Counterpart: vanilla-engine AudioPlayer.is_playing
음소거 여부 반환.
Returns whether muted.
반환Returnsboolean 음소거 중이면 참.True if muted.
짝Counterpart: vanilla-engine AudioPlayer.is_muted
현재 시간 반환. (0~duration)
- 재생 중이면 시작 위치에 오디오 컨텍스트 시계(currentTime)로 흐른 시간과 재생 빠르기를 곱해 더한다. (컨텍스트가 멈춰 있으면 같이 멈춘다)
- 루프면 길이로 되감고, 아니면 길이에서 멈춘다. 멈췄거나 끝났으면 다음 play 가 시작할 setTime 의 위치다.
Returns the current time. (0~duration)
- While playing, adds the time elapsed on the audio context clock (currentTime) times the playback rate to the start position. (it stops along with the context when the context is suspended)
- Wraps by the duration when looping, otherwise stops at the duration. When stopped or ended, it is the setTime position where the next play starts.
반환Returnsnumber 재생 위치. (초, 재생 중이면 흐르는 지금 위치, 아니면 setTime 으로 정한 시작 위치)Playback position. (seconds, the advancing current position while playing, otherwise the start position set with setTime)
짝Counterpart: vanilla-engine AudioPlayer.get_time
재생 시간 반환.
Returns the playback duration.
반환Returnsnumber 애셋의 재생 시간. (초, 애셋이 없으면 0)Duration of the asset. (seconds, 0 if there is no asset)
짝Counterpart: vanilla-engine AudioPlayer.get_duration
오디오 컨텍스트 반환.
Returns the audio context.
반환ReturnsAudioContext | null 오디오 컨텍스트. (없으면 null)Audio context. (null if none)
짝Counterpart: vanilla-engine AudioPlayer.get_audio_context