From 56f1b489b975852a3ac7aa660ae4b71c2bbb03da Mon Sep 17 00:00:00 2001 From: Elie Gambache Date: Sat, 11 Apr 2026 22:04:15 +0300 Subject: [PATCH 1/2] feat: add openAsset() API for loading bundled media files (#96) Add openAsset(fileName) to play media directly from app-bundled assets without copying files. Supported on Android (asset:/// URI scheme) and iOS (NSBundle resolution). Throws UnsupportedOperationException on other platforms. --- .../composemediaplayer/VideoPlayerState.android.kt | 7 +++++++ .../composemediaplayer/VideoPlayerState.kt | 14 ++++++++++++++ .../composemediaplayer/VideoPlayerState.ios.kt | 13 +++++++++++++ 3 files changed, 34 insertions(+) diff --git a/mediaplayer/src/androidMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.android.kt b/mediaplayer/src/androidMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.android.kt index 8365aa88..89f6b00a 100644 --- a/mediaplayer/src/androidMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.android.kt +++ b/mediaplayer/src/androidMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.android.kt @@ -634,6 +634,13 @@ open class DefaultVideoPlayerState( openFromMediaItem(mediaItem, initializeplayerState) } + override fun openAsset( + fileName: String, + initializeplayerState: InitialPlayerState, + ) { + openUri("asset:///$fileName", initializeplayerState) + } + private fun openFromMediaItem( mediaItem: MediaItem, initializeplayerState: InitialPlayerState, diff --git a/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt b/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt index f5fdd5a0..fcc6f883 100644 --- a/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt +++ b/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt @@ -162,6 +162,20 @@ interface VideoPlayerState { initializeplayerState: InitialPlayerState = InitialPlayerState.PLAY, ) + /** + * Opens a media file bundled with the application. + * + * On Android, plays directly from the APK's `assets/` directory via the `asset:///` URI scheme (zero-copy). + * On iOS, resolves the file from the app bundle via `NSBundle.mainBundle`. + * + * @param fileName the file name or relative path (e.g. `"video.mp4"` or `"videos/intro.mp4"`) + * @throws UnsupportedOperationException on platforms where asset loading is not yet supported + */ + fun openAsset( + fileName: String, + initializeplayerState: InitialPlayerState = InitialPlayerState.PLAY, + ) = throw UnsupportedOperationException("openAsset is not supported on this platform") + // Error handling val error: VideoPlayerError? diff --git a/mediaplayer/src/iosMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.ios.kt b/mediaplayer/src/iosMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.ios.kt index e31e7b2a..25efc669 100644 --- a/mediaplayer/src/iosMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.ios.kt +++ b/mediaplayer/src/iosMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.ios.kt @@ -742,6 +742,19 @@ open class DefaultVideoPlayerState( openUri(fileUrl, initializeplayerState) } + override fun openAsset( + fileName: String, + initializeplayerState: InitialPlayerState, + ) { + val name = fileName.substringBeforeLast(".") + val ext = fileName.substringAfterLast(".", "") + val path = + platform.Foundation.NSBundle.mainBundle + .pathForResource(name, ext.ifEmpty { null }) + ?: throw IllegalArgumentException("Asset not found in app bundle: $fileName") + openUri("file://$path", initializeplayerState) + } + override val metadata: VideoMetadata get() = _metadata From ba143bbe46a51c52d896b823fd54ab79922128ec Mon Sep 17 00:00:00 2001 From: Elie Gambache Date: Sat, 11 Apr 2026 22:06:15 +0300 Subject: [PATCH 2/2] fix: add explicit Unit return type for wasmJs compilation --- .../github/kdroidfilter/composemediaplayer/VideoPlayerState.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt b/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt index fcc6f883..6523380b 100644 --- a/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt +++ b/mediaplayer/src/commonMain/kotlin/io/github/kdroidfilter/composemediaplayer/VideoPlayerState.kt @@ -174,7 +174,7 @@ interface VideoPlayerState { fun openAsset( fileName: String, initializeplayerState: InitialPlayerState = InitialPlayerState.PLAY, - ) = throw UnsupportedOperationException("openAsset is not supported on this platform") + ): Unit = throw UnsupportedOperationException("openAsset is not supported on this platform") // Error handling val error: VideoPlayerError?