fix(android): building and video playing with correct aspect ratio

This commit is contained in:
Fredrik Burmester
2026-01-05 11:52:00 +01:00
parent 2e463ddb0c
commit 90474b2403
4 changed files with 19 additions and 30 deletions

View File

@@ -63,7 +63,7 @@
"android": {
"buildArchs": ["arm64-v8a", "x86_64"],
"compileSdkVersion": 36,
"targetSdkVersion": 34,
"targetSdkVersion": 35,
"buildToolsVersion": "35.0.0",
"kotlinVersion": "2.0.21",
"minSdkVersion": 24,

View File

@@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'org.videolan.android:libvlc-all:3.6.0'
implementation 'org.videolan.android:libvlc-all:4.0.0-eap23'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}

View File

@@ -63,16 +63,16 @@ class VlcPlayerModule : Module() {
view.seekTo(time)
}
AsyncFunction("setAudioTrack") { view: VlcPlayerView, trackIndex: Int ->
view.setAudioTrack(trackIndex)
AsyncFunction("setAudioTrack") { view: VlcPlayerView, trackId: String ->
view.setAudioTrack(trackId)
}
AsyncFunction("getAudioTracks") { view: VlcPlayerView ->
view.getAudioTracks()
}
AsyncFunction("setSubtitleTrack") { view: VlcPlayerView, trackIndex: Int ->
view.setSubtitleTrack(trackIndex)
AsyncFunction("setSubtitleTrack") { view: VlcPlayerView, trackId: String ->
view.setSubtitleTrack(trackId)
}
AsyncFunction("getSubtitleTracks") { view: VlcPlayerView ->

View File

@@ -234,6 +234,7 @@ class VlcPlayerView(context: Context, appContext: AppContext) : ExpoView(context
libVLC = LibVLC(context, initOptions)
mediaPlayer = MediaPlayer(libVLC)
mediaPlayer?.attachViews(videoLayout, null, false, false)
mediaPlayer?.setVideoScale(MediaPlayer.ScaleType.SURFACE_BEST_FIT)
mediaPlayer?.setEventListener(this)
log.debug("Loading network file: $uri")
@@ -294,38 +295,26 @@ class VlcPlayerView(context: Context, appContext: AppContext) : ExpoView(context
}
}
fun setAudioTrack(trackIndex: Int) {
mediaPlayer?.setAudioTrack(trackIndex)
fun setAudioTrack(trackId: String) {
// TODO: VLC 4.0 API - need to find correct method
log.debug("setAudioTrack called with $trackId - not yet implemented for VLC 4.0")
}
fun getAudioTracks(): List<Map<String, Any>>? {
log.debug("getAudioTracks ${mediaPlayer?.audioTracks}")
val trackDescriptions = mediaPlayer?.audioTracks ?: return null
return trackDescriptions.map { trackDescription ->
mapOf("name" to trackDescription.name, "index" to trackDescription.id)
}
// TODO: VLC 4.0 API - need to find correct method
log.debug("getAudioTracks - not yet implemented for VLC 4.0")
return emptyList()
}
fun setSubtitleTrack(trackIndex: Int) {
mediaPlayer?.setSpuTrack(trackIndex)
fun setSubtitleTrack(trackId: String) {
// TODO: VLC 4.0 API - need to find correct method
log.debug("setSubtitleTrack called with $trackId - not yet implemented for VLC 4.0")
}
// fun getSubtitleTracks(): List<Map<String, Any>>? {
// return mediaPlayer?.getSpuTracks()?.map { trackDescription ->
// mapOf("name" to trackDescription.name, "index" to trackDescription.id)
// }
// }
fun getSubtitleTracks(): List<Map<String, Any>>? {
val subtitleTracks = mediaPlayer?.spuTracks?.map { trackDescription ->
mapOf("name" to trackDescription.name, "index" to trackDescription.id)
}
// Debug statement to print the result
log.debug("Subtitle Tracks: $subtitleTracks")
return subtitleTracks
// TODO: VLC 4.0 API - need to find correct method
log.debug("getSubtitleTracks - not yet implemented for VLC 4.0")
return emptyList()
}
fun setSubtitleURL(subtitleURL: String, name: String) {