flutter 包含抖动视频闪屏

k7fdbhmy  于 2022-12-27  发布在  Flutter
关注(0)|答案(2)|浏览(174)

我正尝试添加3秒的视频在飞溅的启动画面。所以如何删除白屏前启动画面,而发射屏幕或任何其他建议是欢迎的。
这是我试过的方法

class _MyAppState extends State<MyApp> {
late VideoPlayerController _controller;
@override
void initState() {
  super.initState();
  _controller = VideoPlayerController.asset("assets/video.mp4");
  _controller.addListener(() {
    if (!_controller.value.isPlaying &&
        _controller.value.position.inSeconds >=
            _controller.value.duration.inSeconds) {
      // completion
      _controller.dispose();
      Get.offAll(() => FirstScreen());
    }
  });
  controller.initialize().then(() => setState(() {}));
  _controller.play();
}
@override
void dispose() {
  _controller.dispose();
  super.dispose();
}
@override
Widget build(BuildContext context) {
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);

  return GetMaterialApp(
    debugShowCheckedModeBanner: false,
    home:  Scaffold(
      body: VideoPlayer(_controller),
    ),
  );
}
}
ycl3bljg

ycl3bljg1#

您不能完全删除此屏幕。您唯一能做的就是以某种方式更改它,使其与您的视频播放屏幕匹配。使用https://pub.dev/packages/flutter_native_splash包,使用户感觉不到屏幕变化(使背景相同等)

wswtfjt7

wswtfjt72#

首先在android/app/src/main/res/values中创建styles.xml文件。
styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <!-- Show a Drawable splash screen on the activity. Automatically removed when Flutter draws its first frame -->
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>
    <!-- Theme applied to the Android Window as soon as the process has started.
         This theme determines the color of the Android Window while your
         Flutter UI initializes, as well as behind your Flutter UI while its
         running.  -->
    <style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
        <item name="android:windowBackground">?android:colorBackground</item>
    </style>
</resources>

现在添加您的启动画面内res/drawable文件夹。
AndroidManifest.xml
activity标记中,像这样创建meta-data

<meta-data android:name="io.flutter.app.android.SplashScreenUntilFirstFrame" android:resource="@drawable/splash_screen" />
        <meta-data android:name="flutterEmbedding" android:value="2" />

相关问题