반응형
✅ 1. VideoClip 사용 금지
- ❌ VideoClip (Unity 내부 임포트된 .mp4) 사용 불가
- ❗ 대신 외부 URL 방식만 사용해야 함 (VideoPlayer.url)
✅ 2. VideoPlayer 컴포넌트 사용
- VideoPlayer 컴포넌트를 GameObject에 추가하고
- url 속성에 외부 mp4 경로 입력
예시:
public class WebGLVideoPlayer : MonoBehaviour
{
public VideoPlayer videoPlayer;
void Start()
{
videoPlayer.source = VideoSource.Url;
videoPlayer.url = "https://yourdomain.com/video.mp4";
videoPlayer.audioOutputMode = VideoAudioOutputMode.Direct;
videoPlayer.Play();
}
}
동영상 URL 주의사항
- http:// 또는 https://로 접근 가능한 절대 경로여야 함
- .mp4, .webm, .ogv 등 지원 포맷만 가능
- CORS(Cross-Origin Resource Sharing) 허용되어야 함
(서버에서 Access-Control-Allow-Origin: * 설정 필요)
Audio 설정 옵션
| 모드 | 설명 |
| None | 오디오 없음 |
| Direct | 웹 브라우저에서 직접 오디오 출력 (WebGL에서는 이 방식 추천) |
| AudioSource | AudioSource를 통해 출력 (WebGL에서는 제한적, 3D 사운드 불가) |
동영상 포맷
| 포맷 | 확장자 |
| MPEG-4 | .mp4 |
| QuickTime | .mov |
| WebM | .webm |
| Ogg | .ogv |
✅ .mp4가 가장 안정적
⚠️ 주의 사항 요약
| 항목 | 지원 여부 |
| VideoClip 임포트 사용 | ❌ 미지원 |
| VideoPlayer.url | ✅ 지원 |
| VideoAudioOutputMode.AudioSource | ⚠️ 3D 사운드 미지원 |
| 정확한 프레임 제어 (frameAccurate) | ❌ 미지원 |
| Unity 타임라인 동기화 (captureFramerate) | ❌ 미지원 |
실제 적용 예제 (Unity 에디터에서)
- 빈 GameObject 생성 → VideoPlayer 컴포넌트 추가
- 스크립트 추가:
using UnityEngine;
using UnityEngine.Video;
public class WebGLVideoPlayer : MonoBehaviour
{
private VideoPlayer videoPlayer;
void Start()
{
videoPlayer = GetComponent();
videoPlayer.source = VideoSource.Url;
videoPlayer.url = "https://www.example.com/sample.mp4";
videoPlayer.audioOutputMode = VideoAudioOutputMode.Direct;
videoPlayer.Play();
}
}
참고
- Unity 공식 문서: VideoPlayer 컴포넌트
- CORS 관련 설정 확인: MDN - CORS
반응형
'유니티' 카테고리의 다른 글
| 델파이 조사란? (0) | 2025.08.07 |
|---|---|
| Unity WebGL에서 videoPlayer.url 만들기(CORS 피하기) (0) | 2025.08.07 |
| 유니티 WEBGL 브라우저 URL 가져오기 (0) | 2025.08.07 |
| Unity WebGL ScreenShot 저장하는 방법 (0) | 2025.08.01 |
| 자바스크립트와 유니티 (0) | 2025.08.01 |