搜尋套件、儲存庫與 APP 分類

套件詳情v2.1.0

y_player

YPlayer 是一個 Flutter 套件,提供一個易於使用的 YouTube 影片播放器元件

AndroidiOSmacOSWindowsLinux
近 30 天下載
132
喜歡數
27
Pub 分數
150

安裝套件

flutter pub add y_player

套件介紹

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

YPlayer 是一個 Flutter 套件,可簡化將 YouTube 影片整合至 Flutter 應用程式的過程。它提供了一個可自訂的影片播放器元件,專為跨多個平台無縫嵌入和播放 YouTube 內容而設計。透過最少的設定,開發者可以使用影片 ID 或 URL 顯示 YouTube 影片,支援響應式設計與基本播放控制。該套件利用各平台上的原生 YouTube 播放器,以實現最佳效能與相容性。

適用情境

  • 在應用中嵌入YouTube影片
  • 創建教育內容播放器
  • 建構媒體豐富的 Flutter 應用程式
  • 整合影片教學
  • 開發串流或娛樂應用

主要特色

  • 使用影片 ID 或 URL 簡單嵌入影片
  • 支援 Android、iOS、macOS、Windows 和 Linux
  • 響應式且可自訂的播放器介面
  • 內建播放控制
  • 原生 YouTube 播放器整合

適合對象

  • Flutter 開發人員建構媒體應用
  • 教育類應用程式創作者
  • 帶有影片資料庫的內容平台
  • 需要YouTube影片播放的應用程式

使用建議

  • 需要互聯網連接以加載影片
  • 超出基本控制之外的自定功能有限
  • 取決於 YouTube API 的可用性
  • 某些平台可能需要額外的權限
  • 不適用於離線影片播放

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

YPlayer

Pub

Logo

YPlayer is a Flutter package that provides an easy-to-use YouTube video player widget. It leverages the power of the youtube_explode_dart package for fetching video information.

Features

  • Play YouTube videos directly in your Flutter app
  • Support for fullscreen mode
  • Optional autoplay
  • Video Quality selection
  • Playback speed control
  • Customizable loading and error widgets
  • Easy to use API with play, pause, and stop functionality
  • Callback support for player state changes and progress updates
  • Customizable progress bar colors
  • Improved handling of app lifecycle changes and fullscreen mode
  • Enhanced error handling and recovery
  • Separate handling of video and audio streams for better quality

Installation

Add y_player to your pubspec.yaml file:

dependencies:
  y_player: ^2.0.0

Then run:

flutter pub get

Usage

First, ensure that you initialize the YPlayer in your main.dart:

import 'package:flutter/material.dart';
import 'package:y_player/y_player_main.dart';

void main() {
  YPlayerInitializer.ensureInitialized();
  runApp(MyApp());
}

Here's a simple example of how to use YPlayer in your Flutter app:

import 'package:flutter/material.dart';
import 'package:y_player/y_player_main.dart';

class MyVideoPlayer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('YPlayer Example')),
      body: YPlayer(
        youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
        onStateChanged: (status) {
          print('Player Status: $status');
        },
        onProgressChanged: (position, duration) {
          print('Progress: ${position.inSeconds}/${duration.inSeconds}');
        },
        onControllerReady: (controller) {
          print('Controller is ready!');
        },
      ),
    );
  }
}

Migrating to 2.0.0

Version 2.0.0 introduces significant changes to address the deprecation of muxed streams in YouTube and to improve overall performance. Here are the key changes:

To migrate your existing code:

  1. Update your pubspec.yaml to use version 2.0.0 or later of y_player.

  2. In your main.dart, add the initialization call:

void main() {
  YPlayerInitializer.ensureInitialized();
  runApp(MyApp());
}
  1. Update your YPlayer widget usage. The basic usage remains the same, but some properties have changed:
YPlayer(
  youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
  color: Colors.red, // New property for customizing controls color
  // materialProgressColors and cupertinoProgressColors are no longer available
)
  1. If you were using ChewieController directly, you'll need to update to use YPlayerController instead.

These changes address the deprecation of muxed streams in YouTube and provide a more robust and efficient video playback experience. The separate handling of video and audio streams allows for better quality options and more flexibility in playback.

API Reference

YPlayer

Constructor:

YPlayer({
  Key? key,
  required String youtubeUrl,
  double? aspectRatio,
  bool autoPlay = true,
  Color? color,
  Widget? placeholder,
  Widget? loadingWidget,
  Widget? errorWidget,
  YPlayerStateCallback? onStateChanged,
  YPlayerProgressCallback? onProgressChanged,
  Function(YPlayerController controller)? onControllerReady,
})
YPlayerController

Methods:

  • play(): Starts or resumes video playback.
  • pause(): Pauses video playback.
  • stop(): Stops video playback and resets to the beginning.

Properties:

  • status: Gets the current status of the player (YPlayerStatus enum).
  • position: Gets the current playback position (Duration).
  • duration: Gets the total duration of the video (Duration).
  • isInitialized: Returns true if the player is fully initialized.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

所屬分類

依賴

依賴清單 4 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。