首页 > 解决方案 > Flutter : 视频播放器

问题描述

我正在尝试添加 video_player 插件以在我的项目中显示视频,但项目正在崩溃并在控制台上显示

[错误:flutter/shell/platform/android/platform_view_android_jni_impl.cc(43)] java.lang.RuntimeException:attachToGLContext 期间出错(详见 logcat) E/flutter (15242):在 android.graphics.SurfaceTexture.attachToGLContext(SurfaceTexture .java:286) E/flutter (15242): F/flutter (15242): [致命:flutter/shell/platform/android/platform_view_android_jni_impl.cc(1062)] 检查失败:CheckException(env)。F/libc (15242):致命信号 6 (SIGABRT),tid 15334 (1.raster) 中的代码 -6

这是我使用的方法

VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    super.initState();
    _controller = VideoPlayerController.network(
        'http://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4')
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
        setState(() {});
      });
  }

@override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

Container(
                    height: 200,
                    child: Scaffold(
                      body: Center(
                        child: _controller.value.initialized
                            ? AspectRatio(
                                aspectRatio: _controller.value.aspectRatio,
                                child: VideoPlayer(_controller),
                              )
                            : Container(),
                      ),
                      floatingActionButton: FloatingActionButton(
                        onPressed: () {
                          setState(() {
                            _controller.value.isPlaying
                                ? _controller.pause()
                                : _controller.play();
                          });
                        },
                        child: Icon(
                          _controller.value.isPlaying
                              ? Icons.pause
                              : Icons.play_arrow,
                        ),
                      ),
                    ),),

所以谁能告诉我怎么了!

标签: flutterdartcrashvideo-player

解决方案


推荐阅读