搜索插件、代码仓与 APP 分类

插件详情v1.3.0

video_player_web_hls

video_player 的 Web 平台实现,支持 Chrome 及其他浏览器的 HLS。

Web
近 30 天下载
3.3万
喜欢数
79
Pub 分数
150

安装插件

flutter pub add video_player_web_hls

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个视频播放器包的网页平台实现,为 Chrome 和其他现代浏览器添加了 HLS(HTTP 实时流)支持。它使 Flutter 网页应用能够无缝播放 HLS 流,扩展了核心 video_player 功能以处理自适应流媒体协议。此包专为网页环境设计,因为在这些环境中原生 HLS 支持可能有限或不一致。

适合场景

  • 在 Flutter Web 应用中播放 HLS 流
  • 流式传输实时视频内容
  • 支持自适应码率流媒体
  • 与现有的 video_player 工作流程集成
  • 启用跨浏览器 HLS 兼容性

主要特点

  • Web 上的 HLS 流媒体支持
  • Chrome 和现代浏览器兼容性
  • 与 video_player 的无缝集成
  • 自适应码率播放
  • 轻量且专注的实现

适合对象

  • 面向 Web 平台的 Flutter 开发者
  • 需要HLS视频播放的应用程序
  • 使用自适应流媒体的项目
  • 开发以视频为中心的网络体验的开发者
  • 需要在网页上提供可靠HLS支持的团队

使用建议

  • 仅限网页平台
  • 需要兼容的浏览器(例如 Chrome)
  • 依赖外部的 HLS.js 库
  • 可能需要为复杂的流媒体设置进行额外配置
  • 不适用于移动或桌面平台

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

video_player_web_hls

Version

Supports hls on chrome and other browsers.

Usage

...
dependencies:
  ...
  video_player_web_hls: ^0.1.1
  video_player: ^0.10.10

  ...

Add

 <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"  type="application/javascript"></script>

in index.html above

 <script src="main.dart.js" type="application/javascript"></script>

dart:io

The Web platform does not suppport dart:io, so attempts to create a VideoPlayerController.file will throw an UnimplementedError.

Autoplay

Playing videos without prior interaction with the site might be prohibited by the browser and lead to runtime errors. See also: https://goo.gl/xX8pDD.

Supported Formats

Different web browsers support different sets of video codecs.

Video codecs?

Check MDN's Web video codec guide to learn more about the pros and cons of each video codec.

What codecs are supported?

Visit caniuse.com: 'video format' for a breakdown of which browsers support what codecs. You can customize charts there for the users of your particular website(s).

Here's an abridged version of the data from caniuse, for a Global audience:

MPEG-4/H.264

Data on Global support for the MPEG-4/H.264 video format

WebM

Data on Global support for the WebM video format

Ogg/Theora

Data on Global support for the Ogg/Theora video format

AV1

Data on Global support for the AV1 video format

HEVC/H.265

Data on Global support for the HEVC/H.265 video format

Example

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

void main() => runApp(VideoApp());

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

class _VideoAppState extends State<VideoApp> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    _controller = VideoPlayerController.network(
        'https://test-streams.mux.dev/x36xhzz/x36xhzz.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.initialized
              ? 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();
  }
}

所属分类

依赖

依赖清单 3 项

  • http^1.0.0
  • video_player_platform_interface^6.2.0
  • web>=1.0.0 <2.0.0

源码仓库

使用此插件的项目