0

I have video stream in mjpeg format, so I have read and implmented a lot of ways to work with it, but anything of these ways don't meet my requirments (also I was using webView packages, but now we should implement changing screen oreintation feature and webView dosen't have such thing, so I am using Hero animation to make it works, but in that case my urls with video stream open twice. It dosen't work because it has limitation: only one user can watch stream, in other cases stream will be closed).

So I have found the way to play mjepeg video using Kotlin, and read bout MethodChannel in Flutter, I implemented almost everything as it was said in docs, but it still dosen't work.

Native code:

class MainActivity: FlutterActivity() {

    private val channel = "com.example.my_app"
    private var view: MjpegView? = null
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        MethodChannel(flutterEngine.dartExecutor.binaryMessenger, channel).setMethodCallHandler {
                call, result ->
            if(call.method == "Video") {
                view = findViewById(R.id.mjpegid)
                view!!.isAdjustHeight = true
                view!!.mode1 = MjpegView.MODE_FIT_WIDTH
                view!!.setUrl("http://videos/videos/LiveViewCamera")
                view!!.isRecycleBitmap1 = true
                result.success("it successed!")
            }
            else {
                result.notImplemented()
            }
        }
    }
}

in Flutter:

 final channel = MethodChannel('com.example.my_app');
  String videos = '';
  Future getVideoFromNative() async {
    videos = await channel.invokeMethod('Video');
    print(videos);
    print('are you hehe?');
    setState(() {});
  }

Got this error:

E/MethodChannel#com.example.rosysk_nano_cleaned(17621): Failed to handle method call
E/MethodChannel#com.example.rosysk_nano_cleaned(17621): java.lang.NullPointerException

When I open it in pure Kotlin app, my video and code works perfectly fine

inkwelll075
  • 494
  • 4
  • 19

0 Answers0