微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PlatformException(VideoError, Video player has error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)

如何解决PlatformException(VideoError, Video player has error com.google.android.exoplayer2.ExoPlaybackException: Source error, null, null)

**HI 我正在尝试在我的 Flutter 应用程序中播放实时新闻视频,它是 .m3u8 格式,但出现上述错误。使用所有更新的依赖项。我想在我的 Flutter 应用中播放实时新闻。我有网址你也可以试试。 网址:this video 当我使用另一个带有 .m3u8 的 url 时,它会在 Flutter 应用程序上播放,但是当我粘贴实时 url 代码时,它会抛出上述错误。 **

代码

import 'package:video_player/video_player.dart';
import 'package:Flutter/material.dart';


class VideoApp extends StatefulWidget {
  @override
  _VideoAppState createState() => _VideoAppState();
}

class _VideoAppState extends State<VideoApp> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'http://161.97.162.167:1936/live/tnnnews/playlist.m3u8')
      ..initialize().then((_) {
        // Ensure the first frame is shown after the video is initialized,even before the play button has been pressed.
        setState(() {});
      });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Video Demo',home: Scaffold(
        body: Center(
          child: _controller.value.isInitialized
              ? 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,);
  }

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。