Web Analytics

YouTubePlayer

⭐ 90 stars Korean by IlyaPavlovskii

YouTubePlayer

Maven Central Kotlin Compose Multiplatform

badge-android badge-ios

YouTube 코틀린 멀티플랫폼 플레이어입니다. YouTubePlayer 컴포저블은 Jetpack Compose 앱에 YouTube 비디오 플레이어를 삽입할 수 있게 해줍니다.

기부

저에게 감사하거나 백로그 개발에 기여하고 싶다면 기부하실 수 있습니다. 이것은 제가 프로젝트에 더 집중하는 데 도움이 됩니다.

또한 다음 플랫폼에서 저를 구독하시면 제 주제에 대한 업데이트를 받아보실 수 있습니다.

medium habr

설치

이 라이브러리를 Gradle을 사용하여 프로젝트에 추가할 수 있습니다.

멀티플랫폼 멀티플랫폼 프로젝트에 추가하려면 공통 소스셋에 의존성을 추가하세요:

repositories {
    mavenCentral()
}

kotlin { sourceSets { commonMain { dependencies { implementation("io.github.ilyapavlovskii:youtubeplayer-compose:${latest_version}") } } } }

사용법

val coroutineScope = rememberCoroutineScope()
val hostState = remember { YouTubePlayerHostState() }

when(val state = hostState.currentState) { is YouTubePlayerState.Error -> { Text(text = "Error: ${state.message}") } YouTubePlayerState.Idle -> { // Do nothing, waiting for initialization } is YouTubePlayerState.Playing -> { // Update UI button states } YouTubePlayerState.Ready -> coroutineScope.launch { hostState.loadVideo(YouTubeVideoId("ufKj1sBrC4Q")) } }

YouTubePlayer( modifier = Modifier .fillMaxWidth() .height(300.dp) .gesturesDisabled(), hostState = hostState, options = SimpleYouTubePlayerOptionsBuilder.builder { autoplay(true) mute(true) // autoplay works only with mute for mobile devices controls(false) rel(false) ivLoadPolicy(false) ccLoadPolicy(false) fullscreen = true }, )

컴포저블 함수는 다음의 주요 매개변수를 가집니다:

YouTubePlayerHostState

주요 컨트롤러입니다. 두 가지 주요 공개 구성 요소를 포함합니다:
suspend fun loadVideo(videoId: YouTubeVideoId) = executeCommand(YouTubeExecCommand.LoadVideo(videoId))
suspend fun play() = executeCommand(YouTubeExecCommand.Play)
suspend fun pause() = executeCommand(YouTubeExecCommand.Pause)
suspend fun seekTo(duration: Duration) = executeCommand(YouTubeExecCommand.SeekTo(duration))
suspend fun seekBy(duration: Duration) = executeCommand(YouTubeExecCommand.SeekBy(duration))
suspend fun mute() = executeCommand(YouTubeExecCommand.Mute)
suspend fun unMute() = executeCommand(YouTubeExecCommand.Unmute)
suspend fun setVolume(volume: Int) = executeCommand(YouTubeExecCommand.SetVolume(volume))
suspend fun setPlaybackRate(rate: Float) = executeCommand(YouTubeExecCommand.SetPlaybackRate(rate))
suspend fun toggleFullScreen() = executeCommand(YouTubeExecCommand.ToggleFullscreen)

YouTubePlayerState

YouTube 플레이어 상태는 화면에 표시되는 실제 유튜브 플레이어 상태를 정의합니다. 다음 가능한 상태를 포함합니다:
videoId: YouTubeVideoId - id of the video that is playing
duration: Duration - duration of the video
currentTime: Duration - current time of the video
quality: YouTubeEvent.PlaybackQualityChange.Quality - quality of the video, see [YouTubeEvent.PlaybackQualityChange.Quality]
isPlaying: Boolean - is video playing

YouTubeExecCommand

YouTubeEvent

Sample

Sample

LICENSE

Copyright 2026 Ilia Pavlovskii

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

--- Tranlated By Open Ai Tx | Last indexed: 2026-05-30 ---