Skip to content

Commit

Permalink
Merge branch 'fluttercommunity:master' into fix-pop
Browse files Browse the repository at this point in the history
  • Loading branch information
akmalova authored Jan 16, 2025
2 parents 4238c69 + c2a54c3 commit 39f06c5
Show file tree
Hide file tree
Showing 14 changed files with 296 additions and 106 deletions.
77 changes: 41 additions & 36 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,46 +11,51 @@ on:
- '**.md'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
check-format:
name: Check format using dart format.
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Check format
run: dart format . --set-exit-if-changed

lint:
name: Lint
# Does a sanity check that packages at least pass analysis on the N-1
# versions of Flutter stable if the package claims to support that version.
# This is to minimize accidentally making changes that break old versions
# (which we don't commit to supporting, but don't want to actively break)
# without updating the constraints.
lint_and_build:
name: Flutter Version ${{ matrix.flutter-version }} Lint and Build.
runs-on: ubuntu-latest

strategy:
matrix:
flutter-version:
# The version of Flutter to use should use the minimum Dart SDK version supported by the package,
# refer to https://docs.flutter.dev/development/tools/sdk/releases.
# Note: The version below should be manually updated to the latest second most recent version
# after a new stable version comes out.
- "3.24.5"
- "3.x"
steps:
- name: Checkout code
- name: 📚 Git Checkout
uses: actions/checkout@v4
- name: Flutter Action

- name: 🐦 Setup Flutter
uses: subosito/flutter-action@v2
- name: Install Package Dependencies
with:
flutter-version: ${{ matrix.flutter-version }}
channel: stable
cache: true
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}

- name: 📦 Install Dependencies
run: flutter packages get
- name: Get dependencies for example
run: flutter pub get
working-directory: example
- name: Lint using flutter analyze
run: flutter analyze .

test:
name: Run tests.
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Flutter Action
uses: subosito/flutter-action@v2
- name: Run flutter test
run: |
flutter pub get
flutter test
- name: ✨ Check Formatting
run: dart format --set-exit-if-changed lib

- name: 🕵️ Analyze
run: flutter analyze lib

- name: 🧪 Run Tests
run: flutter test --no-pub --coverage --test-randomize-ordering-seed random

- name: 📁 Upload coverage to Codecov
uses: codecov/codecov-action@v5
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
## [1.9.2]
* Fixed broken Table of Contents links in `README.md`, take two.

## [1.9.1+1]
* Fixed broken Table of Contents links in `README.md`.

## [1.9.1]
* [#872](https://github.com/fluttercommunity/chewie/pull/872): feat: Add showSubtitles flag to control subtitles (#648). Thanks [floodoo](https://github.com/floodoo).
* [#890](https://github.com/fluttercommunity/chewie/pull/890): Fix issue 888. Thanks [diegotori](https://github.com/diegotori).
* **IMPORTANT**: Relaxed the minimum supported Flutter version to `3.24`.
From now on, this library will make a best effort to support the latest `N-1` Flutter version at the minimum.

## [1.9.0]
* **BREAKING CHANGE**: Library now requires at least Flutter version `3.27.0`.

## [1.8.7]
* ⬆️ [#876](https://github.com/fluttercommunity/chewie/pull/876): Add keyboard controls seek forward and backward and fullscreen escape on desktop. Thanks [Ortes](https://github.com/Ortes).

## [1.8.6]
* ⬆️ [#874](https://github.com/fluttercommunity/chewie/pull/874): Add `devtools_options.yaml` configuration files. Thanks [MoRmdn](https://github.com/MoRmdn).

## [1.8.5]
* ⬆️ [#703](https://github.com/fluttercommunity/chewie/pull/703): Adding Seek buttons for Android. Thanks [GyanendroKh](https://github.com/GyanendroKh).
* Upgraded `wakelock_plus` to version `1.2.8`, which uses `web` version `1.0.0`. Thanks [diegotori](https://github.com/diegotori).
Expand Down
93 changes: 74 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,53 @@

The video player for Flutter with a heart of gold.

The [`video_player`](https://pub.dartlang.org/packages/video_player) plugin provides low-level access to video playback. Chewie uses the `video_player` under the hood and wraps it in a friendly Material or Cupertino UI!
The [`video_player`](https://pub.dartlang.org/packages/video_player) plugin provides low-level
access to video playback.

## Preview
Chewie uses the `video_player` under the hood and wraps it in a friendly Material or Cupertino UI!

| MaterialControls | MaterialDesktopControls |
| :--------------: | :---------------------: |
| ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialControls.png) | ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialDesktopControls.png) |
## Table of Contents
1. 🚨 [IMPORTANT!!! (READ THIS FIRST)](#-important-read-this-first)
2. 🔀 [Flutter Version Compatibility](#-flutter-version-compatibility)
3. 🖼️ [Preview](#%EF%B8%8F-preview)
4. ⬇️ [Installation](#%EF%B8%8F-installation)
5. 🕹️ [Using it](#%EF%B8%8F-using-it)
6. ⚙️ [Options](#%EF%B8%8F-options)
7. 🔡 [Subtitles](#-subtitles)
8. 🧪 [Example](#-example)
9.[Migrating from Chewie < 0.9.0](#-migrating-from-chewie--090)
10. 🗺️ [Roadmap](#%EF%B8%8F-roadmap)
11. 📱 [iOS warning](#-ios-warning-)


## 🚨 IMPORTANT!!! (READ THIS FIRST)
This library is __NOT__ responsible for any issues caused by `video_player`, since it's merely a UI
layer on top of it.

In other words, if you see any `PlatformException`s being thrown in your app due to video playback,
they are exclusive to the `video_player` library.

Instead, please raise an issue related to it with the [Flutter Team](https://github.com/flutter/flutter/issues/new/choose).

## 🔀 Flutter Version Compatibility

This library will at the very least make a solid effort to support the second most recent version
of Flutter released. In other words, it will adopt `N-1` version support at
the bare minimum.

However, this cannot be guaranteed due to major changes between Flutter versions. Should that occur,
future updates will be released as major or minor versions as needed.

## 🖼️ Preview

| MaterialControls | MaterialDesktopControls |
|:-------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|
| ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialControls.png) | ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialDesktopControls.png) |

### CupertinoControls
![](https://github.com/brianegan/chewie/raw/master/assets/CupertinoControls.png)

## Installation
## ⬇️ Installation

In your `pubspec.yaml` file within your Flutter Project add `chewie` and `video_player` under dependencies:

Expand All @@ -29,10 +64,12 @@ dependencies:
video_player: <latest_version>
```
## Using it
## 🕹️ Using it
```dart
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';

final videoPlayerController = VideoPlayerController.networkUrl(Uri.parse(
'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4'));

Expand All @@ -59,7 +96,7 @@ void dispose() {
}
```

## Options
## ⚙️ Options

![](https://github.com/brianegan/chewie/raw/master/assets/Options.png)

Expand Down Expand Up @@ -125,13 +162,19 @@ optionsTranslation: OptionsTranslation(
),
```

## Subtitles
## 🔡 Subtitles

> Since version 1.1.0, Chewie supports subtitles.
Chewie allows you to enhance the video playback experience with text overlays. You can add a `List<Subtitle>` to your `ChewieController` and fully customize their appearance using the `subtitleBuilder` function.

### Showing Subtitles by Default

> Since version 1.1.0 chewie supports subtitles. Here you can see how to use them.
Chewie provides the `showSubtitles` flag, allowing you to control whether subtitles are displayed automatically when the video starts. By default, this flag is set to `false`.

You can provide an `List<Subtitle>` and customize your subtitles with the `subtitleBuilder` function.
### Adding Subtitles

Add subtitles to your `ChewieController` like the following example:
Here’s an example of how to add subtitles to your `ChewieController`:

```dart
ChewieController(
Expand All @@ -149,9 +192,10 @@ ChewieController(
index: 1,
start: const Duration(seconds: 10),
end: const Duration(seconds: 20),
text: 'Whats up? :)',
text: 'What’s up? :)',
),
]),
showSubtitles: true, // Automatically display subtitles
subtitleBuilder: (context, subtitle) => Container(
padding: const EdgeInsets.all(10.0),
child: Text(
Expand All @@ -162,9 +206,16 @@ ChewieController(
);
```

The `index` attribute is for if you want to structure your subtitles in your database and provide your indexes here. `end` and `text` are the key attributes.
### Subtitle Structure

The Duration defines which part of your video your subtitles should start and end. For example, if your video is 10 minutes long and you want to add a subtitle between: `00:00` and `00:10`'th of a second:
The `Subtitle` model contains the following key attributes:

- **`index`**: A unique identifier for the subtitle, useful for database integration.
- **`start`**: The starting point of the subtitle, defined as a `Duration`.
- **`end`**: The ending point of the subtitle, defined as a `Duration`.
- **`text`**: The subtitle text that will be displayed.

For example, if your video is 10 minutes long and you want to add a subtitle that appears between `00:00` and `00:10`, you can define it like this:

```dart
Subtitle(
Expand All @@ -175,11 +226,15 @@ Subtitle(
),
```

## Example
### Customizing Subtitles

Use the `subtitleBuilder` function to customize how subtitles are rendered, allowing you to modify text styles, add padding, or apply other customizations to your subtitles.

## 🧪 Example

Please run the app in the [`example/`](https://github.com/brianegan/chewie/tree/master/example) folder to start playing!

## Migrating from Chewie < 0.9.0
## Migrating from Chewie < 0.9.0

Instead of passing the `VideoPlayerController` and your options to the `Chewie` widget you now pass them to the `ChewieController` and pass that later to the `Chewie` widget.

Expand All @@ -205,7 +260,7 @@ final playerWidget = Chewie(
);
```

## Roadmap
## 🗺️ Roadmap

- [x] MaterialUI
- [x] MaterialDesktopUI
Expand All @@ -231,7 +286,7 @@ final playerWidget = Chewie(
- [ ] Screen-Mirroring / Casting (Google Chromecast)


## iOS warning
## 📱 iOS warning

The video_player plugin used by chewie will only work in iOS simulators if you are on flutter 1.26.0 or above. You may need to switch to the beta channel `flutter channel beta`
Please refer to this [issue](https://github.com/flutter/flutter/issues/14647).
Expand Down
3 changes: 3 additions & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
3 changes: 3 additions & 0 deletions example/devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
2 changes: 1 addition & 1 deletion example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Flutter
import UIKit

@UIApplicationMain
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
Expand Down
7 changes: 4 additions & 3 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class _ChewieDemoState extends State<ChewieDemo> {
}

List<String> srcs = [
"https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
"https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4",
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
];

Future<void> initializePlayer() async {
Expand Down Expand Up @@ -126,6 +126,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
];
},
subtitle: Subtitles(subtitles),
showSubtitles: true,
subtitleBuilder: (context, dynamic subtitle) => Container(
padding: const EdgeInsets.all(10.0),
child: subtitle is InlineSpan
Expand Down
9 changes: 9 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class ChewieController extends ChangeNotifier {
this.zoomAndPan = false,
this.maxScale = 2.5,
this.subtitle,
this.showSubtitles = false,
this.subtitleBuilder,
this.customControls,
this.errorBuilder,
Expand Down Expand Up @@ -339,6 +340,7 @@ class ChewieController extends ChangeNotifier {
bool? zoomAndPan,
double? maxScale,
Subtitles? subtitle,
bool? showSubtitles,
Widget Function(BuildContext, dynamic)? subtitleBuilder,
Widget? customControls,
WidgetBuilder? bufferingBuilder,
Expand Down Expand Up @@ -391,6 +393,7 @@ class ChewieController extends ChangeNotifier {
optionsBuilder: optionsBuilder ?? this.optionsBuilder,
additionalOptions: additionalOptions ?? this.additionalOptions,
showControls: showControls ?? this.showControls,
showSubtitles: showSubtitles ?? this.showSubtitles,
subtitle: subtitle ?? this.subtitle,
subtitleBuilder: subtitleBuilder ?? this.subtitleBuilder,
customControls: customControls ?? this.customControls,
Expand Down Expand Up @@ -454,6 +457,12 @@ class ChewieController extends ChangeNotifier {
/// Add a List of Subtitles here in `Subtitles.subtitle`
Subtitles? subtitle;

/// Determines whether subtitles should be shown by default when the video starts.
///
/// If set to `true`, subtitles will be displayed automatically when the video
/// begins playing. If set to `false`, subtitles will be hidden by default.
bool showSubtitles;

/// The controller for the video you want to play
final VideoPlayerController videoPlayerController;

Expand Down
5 changes: 3 additions & 2 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
final position = _latestValue.duration - _latestValue.position;

return Padding(
padding: const EdgeInsets.only(right: 12.0),
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: Text(
'-${formatDuration(position)}',
style: TextStyle(color: iconColor, fontSize: 12.0),
Expand Down Expand Up @@ -641,7 +641,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
}

Future<void> _initialize() async {
_subtitleOn = chewieController.subtitle?.isNotEmpty ?? false;
chewieController.showSubtitles &&
(chewieController.subtitle?.isNotEmpty ?? false);
controller.addListener(_updateState);

_updateState();
Expand Down
2 changes: 0 additions & 2 deletions lib/src/helpers/adaptive_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class AdaptiveControls extends StatelessWidget {
backgroundColor: Color.fromRGBO(41, 41, 41, 0.7),
iconColor: Color.fromARGB(255, 200, 200, 200),
);
default:
return const MaterialControls();
}
}
}
Loading

0 comments on commit 39f06c5

Please sign in to comment.