颤振:直播电视频道播放问题

时间:2020-07-16 18:07:05

标签: flutter streaming channel television

我想播放直播电视频道。这就是为什么我使用flutter_vlc_player 3.0.3。 当我单击该按钮以开始直播电视频道时,有时需要很长时间才能打开,有时无法打开。

但是,当我单击开始直播电视频道的按钮,然后按“ R”以在终端中进行热重装时,此时它会快速打开。

这是我的源代码:

import 'package:flutter/material.dart';
import 'package:flutter_vlc_player/flutter_vlc_player.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _streamUrl;
  VlcPlayerController _vlcViewController;
  @override
  void initState() {
    super.initState();
    _vlcViewController = new VlcPlayerController();
  }

  void _incrementCounter() {
    setState(() {
      if (_streamUrl != null) {
        _streamUrl = null;
      } else {
        _streamUrl =
            "http://tempe.appv.jagobd.com:1934/c5V6mmMyX7RpbEU9Mi8xNy8yMDEOGIDU6RgzQ6NTAgdEoaeFzbF92YWxIZTO0U0ezN1IzMyfvcGVMZEJCTEFWeVN3PTOmdFsaWRtaW51aiPhnPTI/atnws-sg.stream/playlist.m3u8";
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            _streamUrl == null
                ? Container(
                    child: Center(
                      child: RichText(
                        text: TextSpan(children: [
                          TextSpan(
                            text: 'Stream Closed',
                            style: TextStyle(
                                fontSize: 14.0,
                                fontWeight: FontWeight.bold,
                                color: Colors.white,
                                background: Paint()..color = Colors.red),
                          )
                        ]),
                      ),
                    ),
                  )
                : Container(
                    child: new VlcPlayer(
                      url: _streamUrl,
                      controller: _vlcViewController,
                      placeholder: Container(),
                      aspectRatio: 16 / 9,
                    ),
                  )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: Icon(_streamUrl == null ? Icons.play_arrow : Icons.pause),
      ),
    );
  }
}

为什么会这样,我该如何解决?

0 个答案:

没有答案