How can I change the stream screen size as I want?
Description
I'm displaying the RTP stream screen, but I can't position it as I want and can't adjust the size.
mMediaPlayer.aspectRatio
and mMediaPlayer.scale
is not working.
I used videoScale and It looks like this:
- MediaPlayer.ScaleType.SURFACE_FILL
and adjust fragment container size:
It's just cropped and the size doesn't adjust.
- MediaPlayer.ScaleType.SURFACE_ORIGINAL
The layout can be reduced to fit this size, but the disadvantage is that the video size is small, and the aspectRatio does not work.
Here is my videoFragment code(Android compose)
class VideoFragment: Fragment(){
private val mStreamingPath = "rtp://@:8004" //"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mp4"
private val USE_TEXTURE_VIEW = false
private val ENABLE_SUBTITLES = false
private var mVideoLayout: VLCVideoLayout? = null
private var mLibVLC: LibVLC? = null
private var mMediaPlayer: MediaPlayer? = null
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return ComposeView(requireContext()).apply {
setContent {
Box(modifier = Modifier
.border(width = 1.dp, color = Color.Red)
.aspectRatio(4f / 3f)
) {
AndroidView(
modifier = Modifier.matchParentSize(),
factory = { context ->
VLCVideoLayout(context).apply{
mVideoLayout = this
val args: ArrayList<String> = ArrayList()
args.add("-vvv")
args.add("--vout=android-display")
args.add("--file-caching=0")
args.add("--clock-jitter=0")
args.add("--network-caching=0")
args.add("--sub-track=0")
args.add("--drop-late-frames")
args.add("--skip-frames")
args.add("--sout-rtp-proto=rtp")
args.add("--no-autoscale")
mLibVLC = LibVLC(context, args)
mMediaPlayer = MediaPlayer(mLibVLC)
mMediaPlayer?.attachViews(mVideoLayout!!, null, ENABLE_SUBTITLES, USE_TEXTURE_VIEW)
mMediaPlayer?.videoScale = MediaPlayer.ScaleType.SURFACE_FILL // SURFACE_ORIGINAL
val media = Media(mLibVLC, Uri.parse(mStreamingPath))
mMediaPlayer?.media = media
media.release()
mMediaPlayer?.aspectRatio = "16:9" //not working
mMediaPlayer?.scale = 2.0f // not working
mMediaPlayer?.play()
}
})
}
}
}
}
override fun onDestroy() {
super.onDestroy()
mMediaPlayer?.stop()
mMediaPlayer?.detachViews()
mMediaPlayer?.release()
mLibVLC?.release()
}
}
and use dependency implementation 'org.videolan.android:libvlc-all:3.1.12'
Context
App version
Android version
targetSdk 33(app), android version 12(tablet)
Device model
Galaxy Tab A7