메서드
TV SDK에서 ref를 통해 플레이어를 제어하는 메서드를 안내합니다.
사용법
import React, { useRef } from 'react';
import { View, Pressable, Text, StyleSheet } from 'react-native';
import { VpePlayer } from '@sgrsoft/vpe-reactnative-tv-sdk';
import type { PlayerHandle } from '@sgrsoft/vpe-reactnative-tv-sdk';
export default function PlayerWithControls() {
const playerRef = useRef<PlayerHandle>(null);
return (
<View style={styles.container}>
<VpePlayer
ref={playerRef}
accessKey="YOUR_ACCESS_KEY"
options={{
playlist: [{ file: 'https://example.com/video.m3u8' }],
}}
onBack={() => { /* 뒤로가기 */ }}
/>
<View style={styles.controls}>
<Pressable onPress={() => playerRef.current?.play()}>
<Text>재생</Text>
</Pressable>
<Pressable onPress={() => playerRef.current?.pause()}>
<Text>일시정지</Text>
</Pressable>
<Pressable onPress={() => playerRef.current?.currentTime(30)}>
<Text>30초로 이동</Text>
</Pressable>
<Pressable onPress={() => playerRef.current?.next()}>
<Text>다음 영상</Text>
</Pressable>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: { flex: 1, backgroundColor: '#000' },
controls: { flexDirection: 'row', gap: 8, padding: 16 },
});메서드 목록
| 메서드 | 설명 | TV 동작 |
|---|---|---|
play() | 재생 | 정상 동작 |
pause() | 일시정지 | 정상 동작 |
mute() | 음소거 토글 | 정상 동작 |
prev() / next() | 이전/다음 트랙 | 정상 동작 |
currentTime(time) | 시킹 (초) | 정상 동작 |
volume(vol) | 볼륨 설정 | no-op (시스템 볼륨 사용) |
uiHidden() / uiVisible() | UI 숨김/표시 | 정상 동작 |
controlBarActive() / controlBarDeactive() | 컨트롤바 활성화/비활성화 | 정상 동작 |
tokenChange(token) | DRM 토큰 갱신 | 정상 동작 |
layout(layout, merge) | 레이아웃 변경 | 정상 동작 |
changePlayMode(mode) | VOD/Live 모드 전환 | 정상 동작 |
addNextSource(source) | 다음 소스 추가 | 정상 동작 |
addPrevSource(source) | 이전 소스 추가 | 정상 동작 |
isSeeking() | 시킹 상태 조회 | 정상 동작 |
fullscreen() | 전체화면 | no-op (항상 전체화면) |
pip() | PiP | no-op (TV 미지원) |
동적 플레이리스트 추가
// 단일 영상 추가
playerRef.current?.addNextSource({
file: 'https://example.com/new_video.m3u8',
description: { title: '새로운 영상' },
});
// 여러 영상 동시 추가
playerRef.current?.addPrevSource([
{ file: 'https://example.com/video_1.mp4' },
{ file: 'https://example.com/video_2.mp4' },
]);