Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
): Unit = throw UnsupportedOperationException("openAsset is not supported on this platform")

// Error handling
val error: VideoPlayerError?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down