> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-ko/sdk7/media/audio-streaming.md).

# 오디오 스트리밍

씬에서 라이브 오디오 스트림을 재생합니다.

URL에서 오디오를 스트리밍할 수 있습니다. 인터넷 라디오에서 음악을 직접 재생하거나 회의를 장면으로 스트리밍할 때 유용합니다.

{% hint style="info" %}
**💡 팁**: [Creator Hub의 장면 편집기](/creator/content-creator-ko/scene-editor/get-started/about-editor.md), 여기서 **Audio Stream** [스마트 아이템](/creator/content-creator-ko/scene-editor/interactivity/smart-items.md) 을 사용하면 코드를 작성하지 않고도 이 기능을 구현할 수 있습니다.
{% endhint %}

소스의 오디오는 다음 형식 중 하나여야 합니다: `.mp3`, `ogg`, 또는 `aac`. 또한 소스는 *https*  URL(*http*  URL은 지원되지 않음)이어야 하며, 소스에 [외부에서 액세스할 수 있도록 허용하는 CORS 정책(Cross Origin Resource Sharing)이](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) 설정되어 있어야 합니다. 그렇지 않다면 서버를 프록시로 설정하여 스트림을 유효한 방식으로 노출해야 할 수 있습니다.

{% hint style="warning" %}
**📔 참고**: 장면에서 미리 녹음된 사운드를 재생하려면 다음을 참조하세요: [사운드](/creator/content-creator-ko/sdk7/3d/sounds.md).
{% endhint %}

장면에 오디오 스트림을 추가하려면 `AudioStream` 컴포넌트를 엔티티에 추가하면 됩니다:

```ts
const streamEntity = engine.addEntity()

AudioStream.create(streamEntity, {
	url: 'https://icecast.ravepartyradio.org/ravepartyradio-192.mp3',
	playing: true,
	volume: 0.8,
})
```

{% hint style="warning" %}
**📔 참고**: 스트리밍되는 사운드는 위치에 따라 달라지지 않으며, 전체 씬에서 일정한 음량으로 들립니다. 플레이어가 씬 밖으로 나가면 스트리밍 사운드를 전혀 들을 수 없습니다.
{% endhint %}

의 음량을 설정하려면 `AudioStream` 컴포넌트의 `volume` 속성을 변경하세요.

의 컴포넌트를 켜거나 끄려면 `AudioStream` 컴포넌트의 설정을 변경하세요. `playing` 속성을 *true* 또는 *false*.

{% hint style="info" %}
**📔 참고**: 모든 스트리밍 서비스에서 해당 사이트 외부에서 오디오를 재생할 수 있는 것은 아닙니다. 다음은 Decentraland에서 작동하는 몇 가지 예입니다:

```ts
DELTA = "https://cdn.instream.audio/:9069/stream?_=171cd6c2b6e"
GRAFFITI = "https://n07.radiojar.com/2qm1fc5kb.m4a?1617129761=&rj-tok=AAABeIR7VqwAilDFeUM39SDjmw&rj-ttl=5"
ISLA NEGRA = "https://radioislanegra.org/listen/up/basic.aac"
```

{% endhint %}

## 스트림 상태

오디오 스트림의 상태는 다음 중 하나를 사용해 모니터링할 수 있습니다. `audioEventsSystem` (콜백 기반, 권장) 또는 다음을 사용해 폴링할 수 있습니다. `AudioStream.getAudioState()`.

### audioEventsSystem 사용(권장)

스트림 상태가 변경될 때만 실행되는 콜백을 등록합니다. 이는 다음에서 사용하는 시스템과 동일합니다. `AudioSource` 엔티티(참조: [사운드가 끝나는 시점 감지](/creator/content-creator-ko/sdk7/3d/sounds.md#detect-when-a-sound-finishes)).

```ts
import { engine, AudioStream, MediaState } from '@dcl/sdk/ecs'
import { audioEventsSystem } from '@dcl/sdk/ecs'

export function main() {
	const entity = engine.addEntity()

	AudioStream.create(entity, {
		playing: true,
		volume: 1,
		url: 'https://audio-edge-es6pf.mia.g.radiomast.io/ref-128k-mp3-stereo',
	})

	audioEventsSystem.registerAudioEventsEntity(entity, (event) => {
		console.log('Stream state: ', event.state)

		if (event.state === MediaState.MS_ERROR) {
			// Attempt reconnection
		}
	})
}
```

### getAudioState를 사용한 폴링

다음을 사용해 매 프레임 스트림 상태를 폴링할 수도 있습니다. `AudioStream.getAudioState()`. 이 메서드는 다음과 같은 `PBAudioEvent` 객체를 반환합니다(아직 상태가 보고되지 않은 경우 `undefined` ). 객체에는 `state` 필드와 `timestamp` 필드가 있습니다.  `state` 필드의 값은 다음 `MediaState` 열거형 중 하나입니다.

* `MS_NONE`
* `MS_LOADING`
* `MS_READY`
* `MS_PLAYING`
* `MS_PAUSED`
* `MS_BUFFERING`
* `MS_SEEKING`
* `MS_ERROR`

```ts
export function main() {
	const entity = engine.addEntity()

	AudioStream.create(entity, {
		playing: true,
		volume: 1,
		url: 'https://audio-edge-es6pf.mia.g.radiomast.io/ref-128k-mp3-stereo',
	})

	let lastState: MediaState | undefined = undefined
	engine.addSystem(() => {
		const currentState = AudioStream.getAudioState(entity)?.state
		if (lastState !== currentState) {
			console.log('Stream state: ', currentState)
			lastState = currentState

			if (currentState == MediaState.MS_ERROR) {
				// Attempt reconnection
			}
		}
	})
}
```

## 공간 오디오

기본적으로 `AudioStream` 컴포넌트는 전역으로 적용되므로 장면 전체에서 일정한 볼륨으로 들립니다. 플레이어가 장면 밖으로 나가면 스트리밍 오디오가 전혀 들리지 않습니다.

오디오를 공간화하려면 `spatial` 속성을 *true*.

```ts
AudioStream.create(entity, {
	url: 'https://radioislanegra.org/listen/up/stream',
    playing: true,
	spatial: true,
})
```

이제 오디오는 다음 컴포넌트를 소유한 엔티티의 위치에서 재생되며, 플레이어가 가까이 다가갈수록 더 크게 들립니다. `AudioStream` 컴포넌트의 위치에서 재생되며, 플레이어가 가까이 다가갈수록 더 크게 들립니다.

다음 속성을 사용해 공간 오디오를 제어할 수 있습니다.

* `spatialMinDistance`: 오디오가 공간 오디오로 전환되는 최소 거리입니다. 플레이어가 이보다 가까우면 오디오가 최대 음량으로 들립니다. *0* 가 기본값입니다.
* `spatialMaxDistance`: 오디오가 들리는 최대 거리입니다. 플레이어가 이보다 멀리 있으면 오디오 음량이 0이 됩니다. *60* 가 기본값입니다

```ts
const audioStreamEntity = engine.addEntity();

Transform.create(audioStreamEntity, {
    position: Vector3.create(8, 0, 8),
});

AudioStream.create(audioStreamEntity, {
    url: 'https://radioislanegra.org/listen/up/stream',
    playing: true,
    volume: 1.0,
    spatial: true,
    spatialMinDistance: 5,
    spatialMaxDistance: 10
});
```

{% hint style="warning" %}
**📔 참고**: 일부 오디오 형식은 공간 오디오를 지원하지 않습니다. 스트리밍 오디오가 다음 형식 중 하나로 인코딩되어 있는지 확인하세요. *mp3*, *AAC-LC* 또는 *FLAC*.
{% endhint %}

## 오디오 분석

AudioStream에서 실시간 진폭 및 주파수 데이터를 읽어 이퀄라이저나 비트에 맞춰 점멸하는 조명과 같은 반응형 시각 효과를 구현할 수 있습니다. 자세한 내용은 다음을 참조하세요. `AudioStream` 엔티티의 실시간 진폭 및 주파수 데이터를 읽어 이퀄라이저나 비트에 맞춰 점멸하는 조명과 같은 반응형 시각 효과를 구현할 수 있습니다. 자세한 내용은 다음을 참조하세요. [오디오 분석](/creator/content-creator-ko/sdk7/media/audio-analysis.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-ko/sdk7/media/audio-streaming.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
