首页 > 解决方案 > 视频不可见,但音频在 iOS 中工作正常,颤动视频播放器

问题描述

这在 android 设备中运行良好,音频和视频都在相应地播放。但在 iOS 的情况下,只有音频工作,没有视觉效果。我正在 iOS 模拟器中运行该应用程序。我还在 GitHub 上搜索了这个问题,人们建议它可以在真实设备上正常工作,但事实并非如此。

这是我播放视频的整个代码

class UiPathVideoPage extends StatefulWidget {
  final String text;
  UiPathVideoPage({Key key, @required this.text}) : super(key: key);
  @override
  _UiPathVideoPageState createState() => _UiPathVideoPageState();
}

class _UiPathVideoPageState extends State<UiPathVideoPage> {
  VideoPlayerController _controller;
  ProgressDialog pr;
  @override void initState() {
    // TODO: implement initState


    super.initState();




    if(widget.text == 'Telecom') {
      _controller = VideoPlayerController.network(
          'https://firebasestorage.googleapis.com/v0/b/recycler-view-8483d.appspot.com/04ea5f9ca1')
        ..initialize().then((_) {
          // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
          setState(() {});
          _controller.value.isPlaying
              ? _controller.pause()
              : _controller.play();

        });
    }
    if(widget.text == 'Finance'){
      _controller = VideoPlayerController.network(
          'https://firebasestorage.googleapis.com/v0/b/recycler-view-8483d.appspot.com/o/VideoLibrary%273320d38f')
        ..initialize().then((_) {
          // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
          setState(() {});
          _controller.value.isPlaying
              ? _controller.pause()
              : _controller.play();
        });

    }
    if(widget.text == 'Sales'){
      _controller = VideoPlayerController.network(
          'https://firebasestorage.googleapis.com/v0/b/recycler-view-8483d.appspot.com/o/VideoLibraryc498e')
        ..initialize().then((_) {
          // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
          setState(() {});
          _controller.value.isPlaying
              ? _controller.pause()
              : _controller.play();
        });

    }

    if(widget.text == 'Others'){

      _controller = VideoPlayerController.network(
          'https://firebasestorage.googleapis.com/v0/b/recycler-view-8483d.appspot.com/o/VideoLibrary%2Fcea5f9ca1')
        ..initialize().then((_) {
          // Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
          setState(() {});
          _controller.value.isPlaying
              ? _controller.pause()
              : _controller.play();

        });

    }

  }
  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _controller.dispose();
  }
  @override
  Widget build(BuildContext context) {
    pr = new ProgressDialog(context);
    pr.style(
        message: 'Please Waiting...',
        borderRadius: 10.0,
        backgroundColor: Colors.white,
        progressWidget: CircularProgressIndicator(),
        elevation: 10.0,
        insetAnimCurve: Curves.easeInOut,
        progress: 0.0,
        maxProgress: 100.0,
        progressTextStyle: TextStyle(
            color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
        messageTextStyle: TextStyle(
            color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600)
    );
    return Container(
      child: Scaffold(
        backgroundColor: Colors.grey[200],
        appBar: AppBar(
          backgroundColor: Colors.grey[900],
          title: Text(""),
        ),
        body: Center(
            child:
            _controller.value.initialized
                ? AspectRatio(
              aspectRatio: _controller.value.aspectRatio,
              child: VideoPlayer(_controller),
            )
                : Container(
              child: Image.asset('assets/loading.gif'),
            )

        ),


        floatingActionButton: FloatingActionButton(
          onPressed: () {
            setState(() {

              _controller.value.isPlaying
                  ? _controller.pause()
                  : _controller.play();
            });
          },
          child: Icon(
            _controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
          ),
        ),
      ),
    );
  }
}

我正在寻求帮助,在此先感谢

标签: flutter

解决方案


推荐阅读