File tree Expand file tree Collapse file tree
androidMain/kotlin/io/github/kdroidfilter/composemediaplayer
commonMain/kotlin/io/github/kdroidfilter/composemediaplayer
iosMain/kotlin/io/github/kdroidfilter/composemediaplayer Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -634,6 +634,13 @@ open class DefaultVideoPlayerState(
634634 openFromMediaItem(mediaItem, initializeplayerState)
635635 }
636636
637+ override fun openAsset (
638+ fileName : String ,
639+ initializeplayerState : InitialPlayerState ,
640+ ) {
641+ openUri(" asset:///$fileName " , initializeplayerState)
642+ }
643+
637644 private fun openFromMediaItem (
638645 mediaItem : MediaItem ,
639646 initializeplayerState : InitialPlayerState ,
Original file line number Diff line number Diff line change @@ -162,6 +162,20 @@ interface VideoPlayerState {
162162 initializeplayerState : InitialPlayerState = InitialPlayerState .PLAY ,
163163 )
164164
165+ /* *
166+ * Opens a media file bundled with the application.
167+ *
168+ * On Android, plays directly from the APK's `assets/` directory via the `asset:///` URI scheme (zero-copy).
169+ * On iOS, resolves the file from the app bundle via `NSBundle.mainBundle`.
170+ *
171+ * @param fileName the file name or relative path (e.g. `"video.mp4"` or `"videos/intro.mp4"`)
172+ * @throws UnsupportedOperationException on platforms where asset loading is not yet supported
173+ */
174+ fun openAsset (
175+ fileName : String ,
176+ initializeplayerState : InitialPlayerState = InitialPlayerState .PLAY ,
177+ ): Unit = throw UnsupportedOperationException (" openAsset is not supported on this platform" )
178+
165179 // Error handling
166180 val error: VideoPlayerError ?
167181
Original file line number Diff line number Diff line change @@ -742,6 +742,19 @@ open class DefaultVideoPlayerState(
742742 openUri(fileUrl, initializeplayerState)
743743 }
744744
745+ override fun openAsset (
746+ fileName : String ,
747+ initializeplayerState : InitialPlayerState ,
748+ ) {
749+ val name = fileName.substringBeforeLast(" ." )
750+ val ext = fileName.substringAfterLast(" ." , " " )
751+ val path =
752+ platform.Foundation .NSBundle .mainBundle
753+ .pathForResource(name, ext.ifEmpty { null })
754+ ? : throw IllegalArgumentException (" Asset not found in app bundle: $fileName " )
755+ openUri(" file://$path " , initializeplayerState)
756+ }
757+
745758 override val metadata: VideoMetadata
746759 get() = _metadata
747760
You can’t perform that action at this time.
0 commit comments