y_player
YPlayer एक Flutter पैकेज है जो आसानी से उपयोग किया जा सकने वाला YouTube वीडियो प्लेयर विजेट प्रदान करता है
एक फ्लटर पैकेज जो आपके फ्लटर प्रोजेक्ट में कोई यूट्यूब ब्रांडिंग के बिना यूट्यूब प्लेयर को एकीकृत करता है
{"sdk":"flutter"}^1.2.0^1.0.6^1.3.0^3.1.0^5.0.0{"sdk":"flutter"}यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
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.
Add y_player to your pubspec.yaml file:
dependencies:
y_player: ^2.0.0
Then run:
flutter pub get
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!');
},
),
);
}
}
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:
Update your pubspec.yaml to use version 2.0.0 or later of y_player.
In your main.dart, add the initialization call:
void main() {
YPlayerInitializer.ensureInitialized();
runApp(MyApp());
}
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
)
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.
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,
})
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.Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.