flutter Video Player Issue

Viewed 2406

about a month ago I wrote a small class around Video Player Package that I used in an APP to display a video from vimeo. Today I added this class to a new project and when initializing the player I get this: E/flutter (20716): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter (20716): #0 VideoPlayerApi.initialize (package:video_player_platform_interface/messages.dart:177:7) E/flutter (20716): E/flutter (20716): #1 MethodChannelVideoPlayer.init ...

The odd part is it still works flawlessly in my other project using the same identical code/scaffold so I am at a loss at this moment to understand what is going on...

1 Answers

Add this code in your MainActivity

add this Line

import android.content.Context
import android.os.Bundle
import androidx.annotation.NonNull
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin
import io.flutter.plugins.videoplayer.*





class MainActivity : FlutterActivity() {

override fun configureFlutterEngine(@NonNull flutterEngine: 
 FlutterEngine) {
    super.configureFlutterEngine(flutterEngine)
    flutterEngine.getPlugins().add(SharedPreferencesPlugin())
    flutterEngine.getPlugins().add(VideoPlayerPlugin())

}
}
Related