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

GitHub 代码仓ijashuzain/y_player

y_player

一个 Flutter 包,可将 YouTube 播放器集成到您的 Flutter 项目中,且不包含任何 YouTube 品牌元素

y_player 项目封面
星标
8
复刻
10
最近推送(UTC)
2026年8月4日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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.

Ijas Hussain GitHub avatar
GitHub 作者

Ijas Hussain ↗

Zartek TechnologiesNilambur
语言DartC++CMakeRubySwiftNixCHTMLKotlinObjective-C

此仓库发布的插件

使用的依赖

依赖清单 7 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗