You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter的Youtube视频播放器如何固定分辨率及playbackQuality使用问题

问题解答

1. playbackQuality的作用

playbackQuality是YouTube IFrame原生API提供的参数,作用就是主动指定视频的播放分辨率,你没有找到对应属性是因为Flutter的youtube_player封装库没有将它作为初始化参数暴露,而是封装为了控制器的调用方法。

2. 固定240p分辨率的实现方法

你只需要在播放器的onReady回调中调用控制器的setPlaybackQuality方法,传入240p对应的参数值'small'即可生效。

注意:该设置属于优先级建议,不是100%强制生效。如果对应视频没有240p片源、当前网络条件无法支撑该分辨率,YouTube会自动匹配最接近的可用分辨率。

修改后的完整代码

class _VideoScreenState extends State<VideoScreen> {
  late YoutubePlayerController _controller;

  final String _videoId = YoutubePlayer.convertUrlToId(
      'https://www.youtube.com/watch?v=YE7VzlLtp-4')!;

  @override
  void initState() {
    super.initState();
    _controller = YoutubePlayerController(
      initialVideoId: _videoId,
      flags: const YoutubePlayerFlags(
        loop: true,
        autoPlay: true,
        forceHD: false,
        enableCaption: false,
        hideControls: true,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text(
          'Youtube Video Player',
          style: TextStyle(
              color: Colors.blueAccent,
              fontSize: 22.0,
              fontWeight: FontWeight.bold),
        ),
        backgroundColor: Colors.white,
        elevation: 0.0,
      ),
      body: Container(
        padding: const EdgeInsets.symmetric(horizontal: 12.0),
        child: YoutubePlayer(
          controller: _controller,
          aspectRatio: 16 / 9,
          onReady: () {
            print('The Video ID : $_videoId');
            // 固定为240p分辨率
            _controller.setPlaybackQuality('small');
          },
        ),
      ),
    );
  }
}

内容的提问来源于stack exchange,提问作者Ruman mahamud

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 06:24:01