Skip to content

Commit

Permalink
🔊 updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbagyastha committed Aug 13, 2024
1 parent 0008131 commit 63410aa
Show file tree
Hide file tree
Showing 2 changed files with 274 additions and 175 deletions.
260 changes: 98 additions & 162 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,210 +1,146 @@
# Youtube Player IFrame
![YOUTUBE PLAYER IFRAME](packages/youtube_player_flutter/misc/ypf_banner.png)
<p align="center">
<img src="https://raw.githubusercontent.com/sarbagyastha/youtube_player_flutter/master/packages/youtube_player_iframe/screenshots/logo.png" height="100" alt="Youtube Player iFrame" />
</p>
<h2 align="center">Youtube Player iFrame</h2>


[![pub package](https://img.shields.io/pub/v/youtube_player_iframe.svg)](https://pub.dartlang.org/packages/youtube_player_iframe)
[![licence](https://img.shields.io/badge/licence-BSD-orange.svg)](https://github.com/sarbagyastha/youtube_player_flutter/blob/master/LICENSE)
[![Download](https://img.shields.io/badge/download-APK-informational.svg)](https://github.com/sarbagyastha/youtube_player_flutter/releases)
[![Stars](https://img.shields.io/github/stars/sarbagyastha/youtube_player_flutter?color=deeppink)](https://github.com/sarbagyastha/youtube_player_flutter)
[![Top Language](https://img.shields.io/github/languages/top/sarbagyastha/youtube_player_flutter?color=9cf)](https://github.com/sarbagyastha/youtube_player_flutter)
[![effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://dart.dev/guides/language/effective-dart)
[![Web DEMO](https://img.shields.io/badge/Web-DEMO-informational.svg)](https://sarbagyastha.github.io/youtube_player_flutter)
<p align="center">
<a href="https://pub.dartlang.org/packages/youtube_player_iframe"><img src="https://img.shields.io/pub/v/youtube_player_iframe" alt="Pub"></a>
<a href="https://youtube.sarbagyastha.com.np"><img src="https://img.shields.io/badge/Web-Demo-deeppink.svg" alt="Web Demo"></a>
<a href="https://github.com/sarbagyastha/youtube_player_flutter/blob/master/packages/youtube_player_iframe/LICENSE"><img src="https://img.shields.io/badge/License-BSD--3-blueviolet" alt="BSD-3 License"></a>
<a href="https://github.com/sarbagyastha/youtube_player_flutter"><img src="https://img.shields.io/github/languages/top/sarbagyastha/youtube_player_flutter?color=9cf" alt="Top Language"></a>
<a href="https://github.com/sarbagyastha/youtube_player_flutter/issues"><img src="https://img.shields.io/github/issues/sarbagyastha/youtube_player_flutter" alt="GitHub issues"></a>
<a href="https://github.com/sarbagyastha/youtube_player_flutter"><img src="https://img.shields.io/github/stars/sarbagyastha/youtube_player_flutter" alt="Stars"></a>
</p>

Flutter plugin for playing or streaming YouTube videos inline using the official [**iFrame Player API**](https://developers.google.com/youtube/iframe_api_reference).
The package exposes almost all the API provided by **iFrame Player API**. So, it's 100% customizable.
---

Note: This package only provides default youtube web player's skin. If you need Youtube Android player like player with gesture support, use [youtube_player_flutter](https://pub.dartlang.org/packages/youtube_player_flutter) instead.
`youtube_player_flutter` also uses this package as dependency. (Migration Pending)
Flutter plugin for seamlessly playing or streaming YouTube videos inline using the official [**iFrame Player API**](https://developers.google.com/youtube/iframe_api_reference). This package offers extensive customization by exposing nearly the full range of the iFrame Player API's features, ensuring complete flexibility and control.

Supported Platforms:
- **Android**
- **iOS**
- **Web**
<a href="https://youtube.sarbagyastha.com.np"><img src="https://raw.githubusercontent.com/sarbagyastha/youtube_player_flutter/master/packages/youtube_player_iframe/screenshots/demo.png" width="200" alt="Demo Screenshot"></a>

![YOUTUBE PLAYER IFRAME](packages/youtube_player_iframe/youtube_player_iframe.png)

[Click here for WEB DEMO](https://sarbagyastha.github.io/youtube_player_flutter)
## Features 🌟
- ▶️ **Inline Playback**: Provides seamless inline video playback within your app.
- 🎬 **Caption Support**: Fully supports captions for enhanced accessibility.
- 🔑 **No API Key Required**: Easily integrates without the need for an API key.
- 🎛️ **Custom Controls**: Offers extensive support for custom video controls.
- 📊 **Metadata Retrieval**: Capable of retrieving detailed video metadata.
- 📡 **Live Stream Support**: Compatible with live streaming videos.
-**Adjustable Playback Rate**: Allows users to change the playback speed.
- 🛠️ **Custom Control Builders**: Exposes builders for creating bespoke video controls.
- 🎵 **Playlist Support**: Supports both custom playlists and YouTube's native playlist feature.
- 📱 **Fullscreen Gestures**: Enables fullscreen gestures, such as swiping up or down to enter or exit fullscreen mode.

## Salient Features
* Inline Playback
* Supports captions
* No need for API Key
* Supports custom controls
* Retrieves video meta data
* Supports Live Stream videos
* Supports changing playback rate
* Support for both Android and iOS
* Adapts to quality as per the bandwidth
* Exposes builders for building custom controls
* Playlist Support (Both custom and Youtube's playlist)

This package uses [webview_flutter](https://pub.dev/packages/webview_flutter) under-the-hood.

For Web, Flutter's [HtmlElementView](https://api.flutter.dev/flutter/widgets/HtmlElementView-class.html).
For Android & iOS, the package uses [flutter_inappwebview](https://pub.dartlang.org/packages/flutter_inappwebview) under-the-hood.

If your app uses services workers, you may need add additional configuration on the app startup code, in order to ensure that the web view behaviour don't get unstable. To do so, please refer to the [flutter_inappwebview documentation](https://inappwebview.dev/docs/service-worker-api/).

Since *flutter_inappwebview* relies on Flutter's mechanism for embedding Android and iOS views, this plugin might share some known issues tagged with the [platform-views](https://github.com/flutter/flutter/labels/a%3A%20platform-views) label.
## Setup
See [**webview_flutter**'s doc](https://pub.dev/packages/webview_flutter) for the requirements.

## Requirements
* **Android**: `minSdkVersion 17` and add support for `androidx` (see [AndroidX Migration](https://flutter.dev/docs/development/androidx-migration))
* **iOS**: `--ios-language swift`, Xcode version `>= 11`
* **Web**: None
### Using the player
Start by creating a controller.

## Setup
```dart
final _controller = YoutubePlayerController(
params: YoutubePlayerParams(
mute: false,
showControls: true,
showFullscreenButton: true,
),
);
### Web
No Configuration Required.
_controller.loadVideoById(...); // Auto Play
_controller.cueVideoById(...); // Manual Play
_controller.loadPlaylist(...); // Auto Play with playlist
_controller.cuePlaylist(...); // Manual Play with playlist
### iOS
No Configuration Required.
// If the requirement is just to play a single video.
final _controller = YoutubePlayerController.fromVideoId(
videoId: '<video-id>',
autoPlay: false,
params: const YoutubePlayerParams(showFullscreenButton: true),
);
```

[Follow the guide here for complete iOS setup](https://pub.dev/packages/flutter_inappwebview#important-note-for-ios)
Then the player can be used in two ways:

### Android
Set `minSdkVersion` of your `android/app/build.gradle` file to at least 17.
#### Using `YoutubePlayer`
This widget can be used when fullscreen support is not required.

[Follow the guide here for complete Android setup](https://pub.dev/packages/flutter_inappwebview#important-note-for-android)
```dart
YoutubePlayer(
controller: _controller,
aspectRatio: 16 / 9,
);
*Note:* Although the minimum to be set is 17, the player won't play on device with API < 20 (19 if Hybrid Composition is enabled).
For API < 20 devices, you might want to forward the video to be played using YouTube app instead, using packages like `url_launcher` or `android_intent`.
```

#### Using the player
#### Using `YoutubePlayerScaffold`
This widget can be used when fullscreen support for the player is required.

```dart
YoutubePlayerController? _controller;
void initState() {
super.initState();
_controller = YoutubePlayerController(
initialVideoId: videoId,
flags: YoutubePlayerFlags(autoPlay: true, mute: false, startAt: 0),
YoutubePlayerScaffold(
controller: _controller,
aspectRatio: 16 / 9,
builder: (context, player) {
return Column(
children: [
player,
Text('Youtube Player'),
],
);
}
//--------------- in Widget build(BuildContext context) -------------------
YoutubePlayer(
controller: _controller!,
showVideoProgressIndicator: true,
progressIndicatorColor: Colors.amber,
progressColors: ProgressBarColors(
playedColor: Colors.amber,
handleColor: Colors.amberAccent,
),
onReady: () {
_controller!.addListener(listener);
},
),
)
```

See the [example app](example/lib/main.dart) for detailed usage.

## Inherit the controller to descendant widgets
The package provides `YoutubePlayerControllerProvider`.

###For FullScreen Support
```dart
YoutubePlayerBuilder(
player: YoutubePlayer(
showVideoProgressIndicator: true,
controller: _controller!,
),
builder: (context, player) {
return Column(
children: [
// some widgets
player,
],
);
YoutubePlayerControllerProvider(
controller: _controller,
child: Builder(
builder: (context){
// Access the controller as:
// `YoutubePlayerControllerProvider.of(context)`
// or `controller.ytController`.
},
),
),
);
```

## Want to customize the player?
The package provides `YoutubePlayerBuilder`, which can be used to create any custom controls.
The package provides `YoutubeValueBuilder`, which can be used to create any custom controls.

For example, let's create a custom play pause button.
```dart
YoutubePlayerBuilder(
YoutubeValueBuilder(
controller: _controller, // This can be omitted, if using `YoutubePlayerControllerProvider`
builder: (context, value) {
return IconButton(
icon: Icon(
value.playerState == PlayerState.playing
? Icons.pause
: Icons.play_arrow,
value.playerState == PlayerState.playing
? Icons.pause
: Icons.play_arrow,
),
onPressed: () {
value.playerState == PlayerState.playing
? context.ytController.pause()
: context.ytController.play();
},
onPressed: value.isReady
? () {
value.playerState == PlayerState.playing
? context.ytController.pause()
: context.ytController.play();
}
: null,
);
},
);
```

## Available Methods
Methods available for `YoutubePlayerController`.

Method | Description
------------ | ---------------
play() | Plays the currently cued/loaded video.
pause() | Pauses the currently playing video.
stop() | Stops and cancels loading of the current video.
nextVideo() | Loads and plays the next video in the playlist.
previousVideo() | Loads and plays the previous video in the playlist.
playVideoAt(index) | Loads and plays the specified video in the playlist.
load(videoId, {startAt, endAt}) | Loads and plays the specified video.
cue(videoId, {startAt, endAt}) | Loads the specified video's thumbnail and prepares the player to play the video.
loadPlaylist(list, {listType, startAt, index}) | Loads the specified list and plays it.
cuePlaylist(list, {listType, startAt, index}) | Queues the specified list of videos.
mute() | Mutes the player.
unMute() | Unmutes the player.
setVolume(volume) | Sets the volume of player.
seekTo(position, {allowSeekAhead}) | Seeks to a specified time in the video.
setSize(size) | Sets the size in pixels of the player.
setPlaybackRate(rate) | Sets the playback speed for the video.
setLoop(loop) | Enables or disables looping.
setShuffle(shuffle) | Enables or disables shuffling playlist.
reset() | Resets the controller.
convertUrlToId(url, {trimWhiteSpaces}) | Converts fully qualified YouTube Url to video id.
getThumbnail(videoId, {quality, webp}) | Grabs YouTube video's thumbnail for provided video id.
onEnterFullScreen() | Called when player enters fullscreen.
onExitFullScreen() | Called when player exits fullscreen.
invokeJavascript(function) | Invoke custom javascript function.
hideTopMenu() | Hides the title and share icons at the top of player (_May violate YouTube's TOS. Use at your own risk._)
hidePauseOverlay() | Hides the related videos overlay while player is paused (_May violate YouTube's TOS. Use at your own risk._)

## Youtube Player Parameters
All the available parameters.

Parameter | Description
------------ | ---------------
autoPlay | Specifies whether the initial video will automatically start to play when the player loads. **Default = true**
mute | Mutes the player. **Default = false**
captionLanguage | Caption language. **Default = 'en'**
enableCaption | Enables caption by default. **Default = true**
color | Specifies the color that will be used in the player's video progress bar to highlight the amount of the video that the viewer has already seen. **Default = red**
showControls | Indicates whether the video player controls are displayed. **Default = true**
enableKeyboard | Enables or disables the player to respond to keyboard controls. **Default = false**
enableJavaScript | Enables or disables the player to be controlled via IFrame or JavaScript Player API calls. **Default = true**
endAt | Ends the playback in specified time.
showFullscreenButton | Shows or hides the fullscreen button from displaying in the player. **Default = false**
interfaceLanguage | Sets the player's interface language.
showVideoAnnotations | Enables or disables video annotations to be shown by default. **Default = true**
loop | Enables or disables the player to play the initial video again and again. **Default = true**
playlist | Specifies a list of video IDs to be played after initialVideoId.
playsInline | Controls whether videos play inline or fullscreen in an HTML5 player on iOS. **Default = true**
strictRelatedVideos | Enabling ensure that related videos will come from the same channel as the video that was just played. **Default = false**
startAt | Starts the video at specified time.
desktopMode | The controls will be alike Youtube Desktop's controls.
useHybridComposition | Enable [Hybrid Composition](https://github.com/flutter/flutter/wiki/Hybrid-Composition)


## Limitation
For Android: Since the plugin is based on platform views. This plugin requires Android API level 19 or greater.

## License
```
Copyright 2021 Sarbagya Dhaubanjar. All rights reserved.
Copyright 2022 Sarbagya Dhaubanjar. All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Expand Down
Loading

0 comments on commit 63410aa

Please sign in to comment.