badshah badmas
badshah badmas

Reputation: 26

Why drop frames when I play video using Android view in Flutter?

I'm trying to play videos using the libVlc library in Flutter's platform channel.

this is my kotlin code:

MethodChannel(flutterEngine.dartExecutor.binaryMessenger, "Sample_channel").setMethodCallHandler { call, result ->
    if (call.method.equals("play")) {
        setContentView(R.layout.player)
        val videoLayout = findViewById<VLCVideoLayout>(R.id.video_layout)
        var libVLC = LibVLC(context)
        var mediaPlayer = MediaPlayer(libVLC)


        val renderer = RendererLiveData()
        var displayManager = DisplayManager(activity, renderer, true, false, false)
        videoLayout.let {
            mediaPlayer.attachViews(it, displayManager, true, true)
            }

        mediaPlayer.media = Media(libVLC, Uri.parse("http://MY_VIDEO_URL.mkv"))
        mediaPlayer.play()
        result.success("playing")
    }
}

this code works fine. but I would like to show the video element in the flutter's widget. So I used the AndroidView widget. the code looks like below

Dart code:

AndroidView(
    viewType: viewType,
    creationParamsCodec: const BinaryCodec(),
 ),

Kotlin code:

internal class NativeView(  activity: Activity, context: Context, id: Int, creationParams: Map<String?, Any?>?) :   PlatformView{
    private val videoLayout: VLCVideoLayout = VLCVideoLayout(context)

    override fun getView(): VLCVideoLayout {
        return videoLayout
    }

    override fun dispose() {}

    init {

        var libVLC = LibVLC(context)
        var mediaPlayer = MediaPlayer(libVLC)


        val renderer = RendererLiveData()
        var displayManager = DisplayManager(activity, renderer, true, false, false)
        videoLayout.let {
            mediaPlayer.attachViews(it, displayManager, true, true)

        }


        mediaPlayer.media = Media(libVLC, Uri.parse("http:/MY_VIDEO_URL.mkv"))
        mediaPlayer.play()

    }
}

But when I use the AndroidView widget, the video drops frames and plays like low fps video. How can I solve this issue?

Both codes work fine on high-end devices. but low-end devices show performance issues in the second code.

I want to get the same performance as the native screen in Flutter's widget.

Upvotes: 0

Views: 153

Answers (0)

Related Questions