fijkplayer icon indicating copy to clipboard operation
fijkplayer copied to clipboard

播放m3u8的直播流,部分链接频道会没有声音

Open qianzhikang opened this issue 1 year ago • 2 comments

您好,我在使用fijkplayer播放live项目中的频道时,出现了大部分频道没有声音的情况,控制台无报错,正常打印流请求信息,但是模拟器没有声音,只有画面。 没有声音的频道如链接**https://cntv.sbs/live?auth=2307100804&id=cctv2** image 为此我排除了模拟器没有声音的情况(https://cntv.sbs/live?auth=2307100804&id=cctv1有画面有声音) 以下是我的部分代码片段

class _VideoScreenState extends State<myApp> {
  late FijkPlayer player = FijkPlayer();
  var index = 0;
  var len = 0;
  late List<Programe> items;

  _VideoScreenState();

  @override
  void initState() {
    super.initState();
    initializeData();
  }

  void showToast(String message) {
    Fluttertoast.showToast(
      msg: message,
      toastLength: Toast.LENGTH_LONG,
      gravity: ToastGravity.CENTER,
      timeInSecForIosWeb: 1,
      backgroundColor: Colors.black54,
      textColor: Colors.white,
    );
  }

  void initializeData() async {
    items = await loadData();
    len = items.length;
    player.setDataSource(items[index].url, autoPlay: true);
    showToast(items[index].tvgName);
    // 添加对播放器状态的监听
    // player.addListener(_onPlayerStateChanged);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      color: Colors.black,
      child: RawKeyboardListener(
        focusNode: FocusNode(),
        onKey: (RawKeyEvent event) async {
          if (event.runtimeType == RawKeyDownEvent) {
            if (event.logicalKey == LogicalKeyboardKey.arrowUp) {
              // 处理向上键按下事件
              print('上');
              // 如果播放器处于 idle 状态,才进行频道切换
              await player.reset(); // 重置播放器
              // 更新index
              setState(() {
                if (index == len) {
                  index = 0;
                } else {
                  ++index;
                }
              });
              showToast(items[index].tvgName);
              print("change " + "-----------------------" + items[index].url);
              player.setDataSource(items[index].url, autoPlay: true);
            } else if (event.logicalKey == LogicalKeyboardKey.arrowDown) {
              // 处理向下键按下事件
              print('下');
              await player.reset(); // 重制
              setState(() {
                if (index == 0) {
                  index = len;
                } else {
                  --index;
                }
              });
              showToast(items[index].tvgName);
              print("change " + "-----------------------" + items[index].url);
              player.setDataSource(items[index].url, autoPlay: true);
            } 
          }
        },
        child: Container(
          alignment: Alignment.center,
          child: FijkView(
            color: Colors.black,
            player: player,
          ),
        ),
      ),
    ));
  }

}

我非常希望得到你的解答。

qianzhikang avatar Jul 25 '23 01:07 qianzhikang

use media-kit

githubityu avatar Nov 30 '23 08:11 githubityu

我也遇到了,好像是切换播放地址后就会没有声音,默认进入第一个频道有声音,这个是什么原因呢,解决了么?

liyijun0417 avatar Feb 18 '24 09:02 liyijun0417