컨트롤러 제어

웹의 playerRef.current.play() 처럼 명령형 제어나 커스텀 UI 가 필요할 때는 컨트롤러 VPEPlayerController 를 직접 보유하고 뷰 VPEPlayerView 로 렌더링합니다.

기본 예제

컨트롤러는 @StateObject 로 보유합니다. @Published 상태는 SwiftUI 가 자동 관찰하므로 별도 바인딩 없이 UI 가 갱신됩니다.

CustomPlayerScreen.swift
import SwiftUI
import VPEPlayer

struct CustomPlayerScreen: View {
    @StateObject private var player = VPEPlayerController(
        options: [
            "autostart": false,
            "controls": false,          // 내장 컨트롤바 끄고 커스텀 UI로만 제어
            "aspectRatio": "16:9",
            "playlist": [["file": "https://.../master.m3u8"]]
        ],
        accessKey: "YOUR_ACCESS_KEY",
        platform: "pub",
        stage: "real"
    )

    var body: some View {
        VStack {
            VPEPlayerView(controller: player, showsBuiltinControls: false)
                .aspectRatio(16.0 / 9.0, contentMode: .fit)

            HStack {
                Button("재생")    { player.play() }
                Button("일시정지") { player.pause() }
                Button("+10s")    { player.seek(to: player.currentTime + 10) }
                Button("전체화면") { player.enterFullscreen() }
            }
            Text(player.isPlaying ? "재생중" : "정지")   // @Published 자동 관찰
        }
    }
}

생성자

// 딕셔너리 옵션 + 라이선스
VPEPlayerController(options: [String: Any], accessKey: String,
                    platform: String, stage: String, isDev: Bool = false)

// JSON 문자열 옵션 + 라이선스
VPEPlayerController(json: String, accessKey: String,
                    platform: String, stage: String, isDev: Bool = false)

// 라이선스 없이 (저수준)
VPEPlayerController(scopeID: String = UUID().uuidString, options: PlayerOptions = .init())
컨트롤러의 전체 메서드는 메서드 페이지에서, 관찰 가능한 @Published 상태와 Combine 이벤트는 관찰 상태 / 이벤트 페이지에서 확인하세요.
iOS SDKBeta