Skip to content

Commit 4fe316c

Browse files
authored
Merge pull request #103 from KhubaibKhan4/feature/demo_video
-Demo Video Player Setup
2 parents a9b73b0 + 3c2fcb6 commit 4fe316c

File tree

6 files changed

+78
-38
lines changed

6 files changed

+78
-38
lines changed

.kotlin/sessions/kotlin-compiler-12680122139031490636.salive

Whitespace-only changes.

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ androidx-appcompat = "1.7.0"
1313
androidx-activityCompose = "1.10.1"
1414
compose-uitooling = "1.7.8"
1515
kotlinx-coroutines = "1.10.1"
16+
material3Android = "1.3.1"
1617

1718

1819

@@ -37,6 +38,7 @@ kotlinx-coroutines-swing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-
3738
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" }
3839
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
3940
kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinx-coroutines" }
41+
androidx-material3-android = { group = "androidx.compose.material3", name = "material3-android", version.ref = "material3Android" }
4042

4143

4244
[plugins]

mediaplayer-kmp/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ mavenPublishing {
142142
coordinates(
143143
groupId = "io.github.khubaibkhan4",
144144
artifactId = "mediaplayer-kmp",
145-
version = "2.0.7"
145+
version = "2.0.8"
146146
)
147147

148148
pom {

mediaplayer-kmp/src/androidMain/kotlin/YouTubePlayer.android.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import android.annotation.SuppressLint
22
import android.app.Activity
3+
import android.content.Context
34
import android.content.pm.ActivityInfo
45
import android.os.Build
56
import android.os.Handler
@@ -60,6 +61,7 @@ import androidx.media3.exoplayer.ExoPlayer
6061
import androidx.media3.exoplayer.source.ProgressiveMediaSource
6162
import androidx.media3.ui.PlayerView
6263
import coil3.compose.rememberAsyncImagePainter
64+
import com.mediaplayer.kmp.AppContext
6365
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.PlayerConstants
6466
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.AbstractYouTubePlayerListener
6567
import com.pierfrancescosoffritti.androidyoutubeplayer.core.player.listeners.FullscreenListener
@@ -103,8 +105,7 @@ fun ExoPlayerVideoPlayer(
103105
autoPlay: Boolean,
104106
showControls: Boolean
105107
) {
106-
val context = LocalContext.current.findComponentActivity()
107-
val activity = context as ComponentActivity
108+
val context = AppContext.get()
108109
val exoPlayer = remember { ExoPlayer.Builder(context).build() }
109110
var isLoading by remember { mutableStateOf(true) }
110111
var isFullScreen by remember { mutableStateOf(false) }
@@ -146,7 +147,7 @@ fun ExoPlayerVideoPlayer(
146147
if (visibility == View.VISIBLE) {
147148
findViewById<View>(R.drawable.baseline_fullscreen_24)?.setOnClickListener {
148149
isFullScreen = !isFullScreen
149-
handleFullScreen(activity, isFullScreen)
150+
handleFullScreen(context, isFullScreen)
150151
}
151152
}
152153
}
@@ -170,9 +171,9 @@ fun ExoPlayerVideoPlayer(
170171
}
171172
}
172173

173-
fun handleFullScreen(activity: ComponentActivity, isFullScreen: Boolean) {
174+
fun handleFullScreen(activity: Context, isFullScreen: Boolean) {
174175
if (isFullScreen) {
175-
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
176+
(activity as Activity).requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
176177

177178
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
178179
val windowInsetsController = activity.window.insetsController
@@ -188,7 +189,7 @@ fun handleFullScreen(activity: ComponentActivity, isFullScreen: Boolean) {
188189
View.SYSTEM_UI_FLAG_FULLSCREEN
189190
}
190191
} else {
191-
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
192+
(activity as Activity).requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
192193

193194
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
194195
val windowInsetsController = activity.window.insetsController

sample/composeApp/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ kotlin {
4545
commonMain.dependencies {
4646
implementation(compose.runtime)
4747
implementation(compose.foundation)
48+
implementation(compose.material3)
4849
implementation(project(":mediaplayer-kmp"))
4950
}
5051

@@ -72,6 +73,9 @@ android {
7273
versionName = "1.0.0"
7374
}
7475
}
76+
dependencies {
77+
implementation(libs.androidx.material3.android)
78+
}
7579

7680
compose.desktop {
7781
application {

sample/composeApp/src/commonMain/kotlin/sample/app/App.kt

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,21 @@ import VideoPlayer
55
import androidx.compose.foundation.background
66
import androidx.compose.foundation.layout.Box
77
import androidx.compose.foundation.layout.Column
8+
import androidx.compose.foundation.layout.aspectRatio
89
import androidx.compose.foundation.layout.fillMaxSize
910
import androidx.compose.foundation.layout.fillMaxWidth
1011
import androidx.compose.foundation.layout.height
12+
import androidx.compose.material3.Button
13+
import androidx.compose.material3.ExperimentalMaterial3Api
14+
import androidx.compose.material3.ModalBottomSheet
15+
import androidx.compose.material3.Text
16+
import androidx.compose.material3.rememberModalBottomSheetState
1117
import androidx.compose.runtime.Composable
18+
import androidx.compose.runtime.getValue
19+
import androidx.compose.runtime.mutableStateOf
20+
import androidx.compose.runtime.remember
21+
import androidx.compose.runtime.rememberCoroutineScope
22+
import androidx.compose.runtime.setValue
1223
import androidx.compose.ui.Alignment
1324
import androidx.compose.ui.Modifier
1425
import androidx.compose.ui.graphics.Color
@@ -17,41 +28,64 @@ import html_embeded_content.data.EmbedOptions
1728
import html_embeded_content.domain.factory.HtmlContentViewerFactory
1829
import html_embeded_content.domain.factory.HtmlEmbedFeature
1930
import html_embeded_content.presentation.HtmlContentViewerView
31+
import kotlinx.coroutines.launch
2032

2133
@Composable
2234
fun App() {
35+
MainScree(modifier = Modifier.fillMaxSize())
36+
}
37+
38+
@OptIn(ExperimentalMaterial3Api::class)
39+
@Composable
40+
fun MainScree(modifier: Modifier = Modifier) {
41+
var isMedia by remember { mutableStateOf(false) }
42+
val sheetState = rememberModalBottomSheetState()
43+
val coroutineScope = rememberCoroutineScope()
44+
45+
if(isMedia){
46+
ModalBottomSheet(
47+
onDismissRequest = {
48+
isMedia = !isMedia
49+
coroutineScope.launch {
50+
sheetState.hide()
51+
}
52+
},
53+
sheetState = sheetState,
54+
) {
55+
Box(
56+
modifier = Modifier
57+
.fillMaxWidth()
58+
.height(360.dp)
59+
.background(Color.Black),
60+
contentAlignment = Alignment.Center
61+
) {
62+
VideoPlayer(
63+
modifier = Modifier.fillMaxWidth()
64+
.height(340.dp)
65+
.aspectRatio(16/9f)
66+
,
67+
url = "https://freetestdata.com/wp-content/uploads/2022/02/Free_Test_Data_1MB_MP4.mp4",
68+
showControls = true,
69+
autoPlay = false
70+
)
71+
}
72+
73+
}
74+
}
75+
2376
Box(
2477
modifier = Modifier.fillMaxSize().background(Color.White),
2578
contentAlignment = Alignment.Center
2679
) {
27-
Column {
28-
// VideoPlayer(
29-
// modifier = Modifier.fillMaxWidth().height(340.dp),
30-
// url = "https://www.youtube.com/watch?v=AD2nEllUMJw",
31-
// showControls = true,
32-
// autoPlay = false
33-
// )
34-
//
35-
// VideoPlayer(modifier = Modifier.fillMaxWidth().height(340.dp),
36-
// url = "https://freetestdata.com/wp-content/uploads/2022/02/Free_Test_Data_1MB_MP4.mp4", // Automatically Detect the URL, Wether to Play YouTube Video or .mp4 e.g
37-
// showControls = true,
38-
// autoPlay = false
39-
// )
40-
41-
// MediaPlayer(
42-
// modifier = Modifier.fillMaxWidth(),
43-
// url = "https://commondatastorage.googleapis.com/codeskulptor-demos/DDR_assets/Kangaroo_MusiQue_-_The_Neverwritten_Role_Playing_Game.mp3",
44-
// startTime = Color.Black,
45-
// endTime = Color.Black,
46-
// volumeIconColor = Color.Black,
47-
// playIconColor = Color.Blue,
48-
// sliderTrackColor = Color.LightGray,
49-
// sliderIndicatorColor = Color.Blue,
50-
// showControls = true,
51-
// headers = mapOf("String" to ""),
52-
// autoPlay = false
53-
// )
54-
80+
Column(
81+
horizontalAlignment = Alignment.CenterHorizontally
82+
) {
83+
Button(onClick = {
84+
isMedia = !isMedia
85+
coroutineScope.launch { sheetState.show() }
86+
}) {
87+
Text("Open Video Player")
88+
}
5589

5690
val viewer = HtmlContentViewerFactory().createHtmlContentViewer()
5791
val htmlEmbedFeature = HtmlEmbedFeature(viewer)
@@ -63,12 +97,11 @@ fun App() {
6397
onError = { error -> println("Error loading page: $error") }
6498
)
6599
)
100+
66101
HtmlContentViewerView(
67102
viewer = viewer,
68-
modifier = Modifier
69-
.fillMaxSize()
103+
modifier = Modifier.fillMaxSize()
70104
)
71-
72105
}
73106
}
74107
}

0 commit comments

Comments
 (0)