Skip to content

Commit

Permalink
Merge pull request #72 from KhubaibKhan4/fixes
Browse files Browse the repository at this point in the history
-Bug Fixes
  • Loading branch information
KhubaibKhan4 authored Dec 17, 2024
2 parents 382dbd1 + 11b59bd commit d2b4ccd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 94 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You can include MediaPlayer-KMP in your project by adding the following dependen
**Version Catelog**
```
[versions]
mediaPlayerKMP = "2.0.4"
mediaPlayerKMP = "2.0.5"
[libraries]
alert-kmp = { module = "io.github.khubaibkhan4:mediaplayer-kmp", version.ref = "mediaPlayerKMP" }
Expand All @@ -52,7 +52,7 @@ alert-kmp = { module = "io.github.khubaibkhan4:mediaplayer-kmp", version.ref = "


```groovy
implementation("io.github.khubaibkhan4:mediaplayer-kmp:2.0.4")
implementation("io.github.khubaibkhan4:mediaplayer-kmp:2.0.5")
```


Expand Down
2 changes: 1 addition & 1 deletion mediaplayer-kmp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ mavenPublishing {
coordinates(
groupId = "io.github.khubaibkhan4",
artifactId = "mediaplayer-kmp",
version = "2.0.4"
version = "2.0.5"
)

pom {
Expand Down
91 changes: 0 additions & 91 deletions mediaplayer-kmp/src/androidMain/kotlin/YouTubePlayer.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -562,94 +562,3 @@ fun isAudioFile(url: String?): Boolean {
Regex(".*(radio|stream|icecast|shoutcast|audio|listen).*", RegexOption.IGNORE_CASE)
) == true
}

@Composable
actual fun ReelsView(
videoUrls: List<String>,
modifier: Modifier,
autoPlay: Boolean,
onInteraction: (Int, String) -> Unit
) {
val pagerState = rememberPagerState(pageCount = {videoUrls.size})

VerticalPager(
state = pagerState,
modifier = modifier
.fillMaxSize()
.background(Color.Black)
) { pageIndex ->
ReelsPage(
videoUrl = videoUrls[pageIndex],
pageIndex = pageIndex,
autoPlay = autoPlay && pagerState.currentPage == pageIndex,
onInteraction = onInteraction
)
}
}

@Composable
fun ReelsPage(
videoUrl: String,
pageIndex: Int,
autoPlay: Boolean,
onInteraction: (Int, String) -> Unit,
isPlaying: (Boolean) -> Unit = {},
isLoading: (Boolean) -> Unit = {},
onVideoEnded: () -> Unit = {},
) {
Box(
modifier = Modifier
.fillMaxSize()
.background(Color.Black)
) {
YoutubeVideoPlayer(
youtubeURL = videoUrl,
autoPlay = autoPlay,
modifier = Modifier.fillMaxSize(),
isPlaying = isPlaying,
isLoading = isLoading,
onVideoEnded = onVideoEnded
)

Column(
verticalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Text(
text = "Video $pageIndex",
color = Color.White,
textAlign = TextAlign.Start,
style = MaterialTheme.typography.titleLarge
)

Row(
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = "❤️ Like",
color = Color.White,
modifier = Modifier.clickable {
onInteraction(pageIndex, "Like")
}
)
Text(
text = "💬 Comment",
color = Color.White,
modifier = Modifier.clickable {
onInteraction(pageIndex, "Comment")
}
)
Text(
text = "📤 Share",
color = Color.White,
modifier = Modifier.clickable {
onInteraction(pageIndex, "Share")
}
)
}
}
}
}
24 changes: 24 additions & 0 deletions mediaplayer-kmp/src/jvmMain/kotlin/DesktopWebView.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.awt.SwingPanel
import javafx.application.Platform
import javafx.concurrent.Worker
import javafx.embed.swing.JFXPanel
import javafx.scene.Scene
import javafx.scene.web.WebView
import javax.swing.JPanel

fun initJavaFX() {
System.setProperty("prism.order", "sw")
System.setProperty("prism.verbose", "true")
}
@Composable
fun DesktopWebView(
modifier: Modifier,
url: String,
autoPlay: Boolean
) {
val jPanel: JPanel = remember { JPanel() }
val jfxPanel = JFXPanel()

SwingPanel(
factory = {
jfxPanel.apply { buildWebView(url,autoPlay) }
jPanel.add(jfxPanel)
},
modifier = modifier,
)

DisposableEffect(url) { onDispose { jPanel.remove(jfxPanel) } }
}
private fun JFXPanel.buildWebView(url: String, autoPlay: Boolean) {
initJavaFX()
Platform.runLater {
Expand Down

0 comments on commit d2b4ccd

Please sign in to comment.