Web Analytics

YouTubePlayer

⭐ 92 stars Arabic by IlyaPavlovskii

🌐 اللغة

مشغل اليوتيوب

Maven Central Kotlin Compose Multiplatform

badge-android badge-ios

مشغل YouTube لمنصة كوتلن متعددة المنصات. يتيح لك المركب YouTubePlayer تضمين مشغل فيديو YouTube في تطبيق Jetpack Compose الخاص بك.

تبرع

إذا كنت ترغب في شكري أو المساهمة في تطوير قائمة المهام، يمكنك التبرع لي. هذا يساعدني على التركيز أكثر على المشروع.

يمكنك أيضاً متابعتي على المنصات التالية لمتابعة أي تحديثات حول مواضيعي

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 تحدد حالة مشغل 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

مثال

مثال

الرخصة

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-06-12 ---