搜尋套件、儲存庫與 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

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個網頁平台實作的 video_player 套件,為 Chrome 和其他現代瀏覽器新增 HLS(HTTP Live Streaming)支援。它讓 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

原始碼儲存庫

使用此套件的專案