generated from Kotlin/multiplatform-library-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from kkostov/add-play-remote-audio
Add play remote audio
- Loading branch information
Showing
20 changed files
with
198 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
gadulka/src/androidMain/kotlin/GadulkaAudioPlayer.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package eu.iamkonstantin.kotlin.gadulka | ||
|
||
import android.media.MediaPlayer | ||
|
||
import android.content.Context | ||
import androidx.media3.common.MediaItem | ||
import androidx.media3.exoplayer.ExoPlayer | ||
|
||
// | ||
//actual class AudioPlayer(private val context: Context) { | ||
// | ||
// private val mediaPlayer = ExoPlayer.Builder(context).build() | ||
// private val mediaItems = soundResList.map { | ||
// MediaItem.fromUri(Res.getUri(it)) | ||
// } | ||
// | ||
// init { | ||
// mediaPlayer.prepare() | ||
// } | ||
// | ||
// @OptIn(ExperimentalResourceApi::class) | ||
// actual fun playSound(id: Int) { | ||
// mediaPlayer.setMediaItem(mediaItems[id]) | ||
// mediaPlayer.play() | ||
// } | ||
// | ||
// actual fun release() { | ||
// mediaPlayer.release() | ||
// } | ||
//} | ||
// | ||
actual class GadulkaPlayer(private val context: Context) { | ||
private val mediaPlayer = ExoPlayer.Builder(context).build() | ||
|
||
init { | ||
mediaPlayer.prepare() | ||
} | ||
|
||
actual fun play(url: String) { | ||
if (mediaPlayer.isPlaying) mediaPlayer.pause() | ||
val mediaItem = MediaItem.fromUri(url) | ||
mediaPlayer.setMediaItem(mediaItem) | ||
mediaPlayer.play() | ||
} | ||
|
||
actual fun release() { | ||
mediaPlayer.release() | ||
} | ||
|
||
actual fun stop() { | ||
mediaPlayer.pause() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package eu.iamkonstantin.kotlin.gadulka | ||
|
||
expect class GadulkaPlayer { | ||
fun play(url: String) | ||
|
||
fun stop() | ||
|
||
fun release() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package eu.iamkonstantin.kotlin.gadulka | ||
|
||
import platform.AVFoundation.* | ||
import platform.Foundation.NSURL | ||
|
||
actual class GadulkaPlayer { | ||
private var player: AVPlayer? = null | ||
|
||
actual fun play(url: String) { | ||
release() | ||
|
||
val nsUrl = NSURL(string = url) | ||
player = AVPlayer.playerWithURL(nsUrl) | ||
player?.play() | ||
} | ||
|
||
actual fun release() { | ||
player?.pause() | ||
player = null | ||
} | ||
|
||
actual fun stop() { | ||
player?.pause() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package eu.iamkonstantin.kotlin.gadulka | ||
|
||
import javafx.application.Platform | ||
import javafx.embed.swing.JFXPanel | ||
import javafx.scene.media.Media | ||
import javafx.scene.media.MediaPlayer | ||
import java.net.URI | ||
|
||
actual class GadulkaPlayer { | ||
var playerState: MediaPlayer? = null | ||
|
||
init { | ||
// Ensure JavaFX runtime is initialized | ||
JFXPanel() | ||
} | ||
|
||
actual fun play(url: String) { | ||
release() | ||
|
||
Platform.runLater { | ||
try { | ||
val media = Media(URI(url).toString()) | ||
playerState = MediaPlayer(media).apply { | ||
setOnReady { | ||
println("Ready, playing..") | ||
play() | ||
} | ||
setOnEndOfMedia { | ||
println("End of media") | ||
} | ||
setOnError { | ||
println("Error occurred: ${this.error?.message}") | ||
} | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} | ||
|
||
actual fun release() { | ||
playerState?.stop() | ||
playerState = null | ||
} | ||
|
||
actual fun stop() { | ||
playerState?.stop() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
[versions] | ||
agp = "8.5.0" | ||
kotlin = "2.0.20" | ||
agp = "8.5.2" | ||
kotlin = "2.0.21" | ||
android-minSdk = "24" | ||
android-compileSdk = "34" | ||
media3_version = "1.4.1" | ||
|
||
[libraries] | ||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } | ||
androix-media3-exploplayer = { group = "androidx.media3", name = "media3-exoplayer", version.ref = "media3_version" } | ||
|
||
|
||
[plugins] | ||
androidLibrary = { id = "com.android.library", version.ref = "agp" } | ||
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } | ||
vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } | ||
osdetector = { id = "com.google.osdetector", version = "1.7.3" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
|
||
# Sets and commits the version coordinate of the library based on the provided input. | ||
# The script expects the version to be a valid semversion e.g. 1.0.0 | ||
|
||
|
||
# Check if two arguments are passed | ||
if [ -z "$1" ] || [ -z "$2" ]; then | ||
echo "No input provided. Usage: ./setversion.sh <semver> file/to/update" | ||
exit 1 | ||
fi | ||
|
||
# Assign the first argument to a variable | ||
NEW_VERSION="$1" | ||
FILE_PATH="$2" | ||
|
||
echo "Updating veresion to '${NEW_VERSION}' in '${FILE_PATH}'." | ||
|
||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
# macOS requires an empty string argument after -i to edit in place without backup | ||
sed -i '' "s/^version = .*$/version = \"${NEW_VERSION}\"/g" "${FILE_PATH}" | ||
else | ||
# Linux | ||
sed -i "/version = /c\version = \"${NEW_VERSION}\"" "${FILE_PATH}" | ||
fi | ||
|
||
echo "Version updated to ${NEW_VERSION}." |