apivideo / api.video-flutter-live-stream

Flutter RTMP live stream client. Made with ♥ by api.video
MIT License
70 stars 41 forks source link

[Bug]: Failed to handle method call #48

Closed imsujan276 closed 9 months ago

imsujan276 commented 10 months ago

Version

v1.1.1

Which operating systems have you used?

Environment that reproduces the issue

Google pixel 5 Android 12

Is it reproducible in the example application?

Yes

RTMP Server

api.video

Reproduction steps

  1. Start the stream
  2. stop the stream
  3. the error gets caught and get seen in the console

Expected result

there should be no errors

Actual result

got the following error

D/HostConnection(14127): HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_YUV_Cache ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
D/EGL_emulation(14127): eglCreateContext: 0x77d2d4696a10: maj 3 min 0 rcv 3
D/EGL_emulation(14127): eglMakeCurrent: 0x77d2d4696a10: ver 3 0 (tinfo 0x77d4f66bc300) (first time)
E/MethodChannel#video.api.livestream/controller(14127): Failed to handle method call
E/MethodChannel#video.api.livestream/controller(14127): java.lang.NullPointerException
E/MethodChannel#video.api.livestream/controller(14127):     at video.api.flutter.livestream.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.kt:101)
E/MethodChannel#video.api.livestream/controller(14127):     at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/MethodChannel#video.api.livestream/controller(14127):     at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/MethodChannel#video.api.livestream/controller(14127):     at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/MethodChannel#video.api.livestream/controller(14127):     at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/MethodChannel#video.api.livestream/controller(14127):     at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#video.api.livestream/controller(14127):     at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#video.api.livestream/controller(14127):     at android.os.Looper.loopOnce(Looper.java:201)
E/MethodChannel#video.api.livestream/controller(14127):     at android.os.Looper.loop(Looper.java:288)
E/MethodChannel#video.api.livestream/controller(14127):     at android.app.ActivityThread.main(ActivityThread.java:7839)
E/MethodChannel#video.api.livestream/controller(14127):     at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#video.api.livestream/controller(14127):     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/MethodChannel#video.api.livestream/controller(14127):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
2
W/System  (14127): A resource failed to call release. 
D/BufferPoolAccessor2.0(14127): bufferpool2 0x77d324753378 : 0(0 size) total buffers - 0(0 size) used buffers - 594/599 (recycle/alloc) - 7/1188 (fetch/transfer)
D/BufferPoolAccessor2.0(14127): evictor expired: 1, evicted: 1
E/flutter (14127): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, null, null, java.lang.NullPointerException
E/flutter (14127):  at video.api.flutter.livestream.MethodCallHandlerImpl.onMethodCall(MethodCallHandlerImpl.kt:101)
E/flutter (14127):  at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:267)
E/flutter (14127):  at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
E/flutter (14127):  at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
E/flutter (14127):  at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
E/flutter (14127):  at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (14127):  at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (14127):  at android.os.Looper.loopOnce(Looper.java:201)
E/flutter (14127):  at android.os.Looper.loop(Looper.java:288)
E/flutter (14127):  at android.app.ActivityThread.main(ActivityThread.java:7839)
E/flutter (14127):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter (14127):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/flutter (14127):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/flutter (14127): )
E/flutter (14127): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter (14127): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter (14127): <asynchronous suspension>
E/flutter (14127): 

Additional context

No response

Relevant logs output

No response

ThibaultBee commented 9 months ago

Hi, Thanks for reporting the issue. I guess that the issue is due to a force unwrap of the flutterView (see https://github.com/apivideo/api.video-flutter-live-stream/blob/c0a17de876343585fccf656eb471598c18e58f36/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt#L100) For dispose and stops methods, this should do nothing if flutterView is null

I don't know why this happen on your side, when does it crash? Have you call dispose before?

ThibaultBee commented 9 months ago

Could you test with fix https://github.com/apivideo/api.video-flutter-live-stream/commit/5e69d340f433ae6e2d8abd332efd44ccfc37906e

imsujan276 commented 9 months ago

Thank you @ThibaultBee. That fixed the closed issue.

But I am getting another issue while starting the streaming.

THIS HAPPENS THE FIRST TIME THE STREAMING. LATER THIS ISSUES DOES NOT COME

On page load, I am calling the init() to initialize the controller. Once initialized, I am starting the streaming.
Am I doing something wrong here?

E/flutter ( 9243): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(failed_to_start_preview, Video has not been configured!, null, null)
E/flutter ( 9243): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter ( 9243): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter ( 9243): <asynchronous suspension>

code I am using

init(){
controller = createLiveStreamController();
    controller!.initialize().then((_) {
      log('VideoStream: Initialized');
      startStreaming();
      listenToInternetConnection();
    }).catchError((e) => showSnackbar(e.toString()));
}

ApiVideoLiveStreamController createLiveStreamController() {
    return ApiVideoLiveStreamController(
      initialAudioConfig: rtmsConfig.audioConfig,
      initialVideoConfig: rtmsConfig.videoConfig,
      onConnectionSuccess: () {
        log('VideoStream: Connection succeeded');
      },
      onConnectionFailed: (error) {
        log('VideoStream: Connection failed: $error');
      },
      onDisconnection: () {
        log('VideoStream: Connection Disconnected');
      },
      onError: (err) {
        log('VideoStream: Connection Error: $err');
      },
    );
  }

Future<void> startStreaming() async {
    try {
      setLiveStatus(LiveStatus.loading);
      await controller?.startStreaming(
        url: rtmsConfig.rtmpUrl,
        streamKey: rtmsConfig.rtmpStreamKey,
      );
      log('VideoStream: Stream Started');
    } catch (e) {
      log('VideoStream: Failed to start stream: $e');
    }
  }
ThibaultBee commented 9 months ago

Hi, I don't reproduced this behavior on my side. Could you fork this repo and modify the example code to show me how to reproduce?

imsujan276 commented 9 months ago

I am not doing any extra configurations.

just calling the init function in initState and everything is the same.

To reproduce the error,

  1. clear/uninstall previously installed app
  2. run the example
  3. after asking for permission, you can see the error message in the console
ThibaultBee commented 9 months ago

Ok, it is an issue with the permissions. Could you test: https://github.com/apivideo/api.video-flutter-live-stream/commit/42f8a0e11eb12419fd128daeca56d6f46a9b644f?

imsujan276 commented 9 months ago

Now, I am not able to build the app

Getting this error

flutter run -t lib/main_prod.dart --flavor prod
Launching lib/main_prod.dart on sdk gphone64 x86 64 in debug mode...
e: apivideo_live_stream/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt:73:21 Val cannot be reassigned
e: apivideo_live_stream/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt:83:21 Val cannot be reassigned
e: apivideo_live_stream/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt:92:48 No value passed for parameter 'onSuccess'
e: apivideo_live_stream/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt:92:48 No value passed for parameter 'onError'
e: apivideo_live_stream/android/src/main/kotlin/video/api/flutter/livestream/MethodCallHandlerImpl.kt:156:21 Val cannot be reassigned

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':apivideo_live_stream:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
Running Gradle task 'assembleProdDebug'...                          5.0s
Exception: Gradle task assembleProdDebug failed with exit code 1
ThibaultBee commented 9 months ago

Hi,

CI properly runs (see https://github.com/apivideo/api.video-flutter-live-stream/actions/runs/7787509905). Could you clone the project from scratch?

imsujan276 commented 9 months ago

Yes now i am able to run the app.

But getting new error after giving the permission

E/flutter ( 6246): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(failed_to_set_audio_config, Video has not been configured!, null, null)
E/flutter ( 6246): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:651:7)
E/flutter ( 6246): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:322:18)
E/flutter ( 6246): <asynchronous suspension>
E/flutter ( 6246): 
ThibaultBee commented 9 months ago

This could happens because startPreview is called directly by didChangeAppLifecycleState although video configuration have not been applied. Anyway, internally startPreview will be called after the video configuration is set.

But failed_to_set_audio_config should be failed_to_start_preview.

It is just a message and I guess the behavior is correct now.

imsujan276 commented 9 months ago

So, can I leave it as it is?

Will it not cause issues in the future?

ThibaultBee commented 9 months ago

To avoid the error to pop, you can do something like when you call startPreview (ie in didChangeAppLifecycleState)

      if (_controller.isInitialized) {
        _controller.startPreview();
      }
ThibaultBee commented 9 months ago

Alternatively, you might register didChangeAppLifecycleState when the controller has been initialized. But that depends on your implementation.

ThibaultBee commented 9 months ago

This issue is solved in v1.2.0. Please reopen it if you feel something is missing.