Skip to content

Commit 4c49feb

Browse files
committed
Merge commit 'c2a54c3affbc74ba7f514958e34087e7788417ab' into custom-lg
* commit 'c2a54c3affbc74ba7f514958e34087e7788417ab': chewie, version 1.9.2. Fixed broken Table of Contents links in README.md, take two. Fixed broken Table of Contents links in README.md, take two. chewie, version 1.9.1+1. Fixed broken Table of Contents links in README.md. Fixed broken Table of Contents links in README.md. chewie, version 1.9.1. Fixes issue fluttercommunity#888. Added Github Workflow concurrency. Added more descriptive name to new task, take three. Added minimum Dart version supported by minimum Flutter version. Added more descriptive name to new task, take two. Added more descriptive name to new task. Added default flutter version inputs to use with the job matrix. Added revamped workflow that now tests this library against both the current and N-1 version of Flutter. Ignoring withOpacity for the entire Dart extensions file. Updated readme. Added withOpacityCompact extension to ensure compatibility with Flutter versions below 3.27. Rename showSubtitlesPerDefault flag to showSubtitles feat: Add `showSubtitlesPerDefault` flag to control subtitles (fluttercommunity#648) feat: Add `showSubtitlesPerDefault` flag to control subtitles (fluttercommunity#648) # Conflicts: # example/lib/app/app.dart
2 parents e4879ba + c2a54c3 commit 4c49feb

File tree

13 files changed

+187
-69
lines changed

13 files changed

+187
-69
lines changed

.fvm/flutter_sdk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/Users/lg/.fvm/versions/3.19.6
1+
/Users/lg/.fvm/versions/3.27.4

.fvm/fvm_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"flutterSdkVersion": "3.19.6"
2+
"flutterSdkVersion": "3.27.4"
33
}

.fvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"flutter": "3.19.6",
2+
"flutter": "3.27.4",
33
"flavors": {}
44
}

.github/workflows/ci.yml

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,51 @@ on:
1111
- '**.md'
1212
workflow_dispatch:
1313

14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
1418
jobs:
15-
check-format:
16-
name: Check format using dart format.
17-
runs-on: ubuntu-latest
18-
19-
steps:
20-
- name: Checkout code
21-
uses: actions/checkout@v4
22-
- name: Flutter Action
23-
uses: subosito/flutter-action@v2
24-
- name: Check format
25-
run: dart format . --set-exit-if-changed
26-
27-
lint:
28-
name: Lint
19+
# Does a sanity check that packages at least pass analysis on the N-1
20+
# versions of Flutter stable if the package claims to support that version.
21+
# This is to minimize accidentally making changes that break old versions
22+
# (which we don't commit to supporting, but don't want to actively break)
23+
# without updating the constraints.
24+
lint_and_build:
25+
name: Flutter Version ${{ matrix.flutter-version }} Lint and Build.
2926
runs-on: ubuntu-latest
30-
27+
strategy:
28+
matrix:
29+
flutter-version:
30+
# The version of Flutter to use should use the minimum Dart SDK version supported by the package,
31+
# refer to https://docs.flutter.dev/development/tools/sdk/releases.
32+
# Note: The version below should be manually updated to the latest second most recent version
33+
# after a new stable version comes out.
34+
- "3.24.5"
35+
- "3.x"
3136
steps:
32-
- name: Checkout code
37+
- name: 📚 Git Checkout
3338
uses: actions/checkout@v4
34-
- name: Flutter Action
39+
40+
- name: 🐦 Setup Flutter
3541
uses: subosito/flutter-action@v2
36-
- name: Install Package Dependencies
42+
with:
43+
flutter-version: ${{ matrix.flutter-version }}
44+
channel: stable
45+
cache: true
46+
cache-key: flutter-:os:-:channel:-:version:-:arch:-:hash:-${{ hashFiles('**/pubspec.lock') }}
47+
48+
- name: 📦 Install Dependencies
3749
run: flutter packages get
38-
- name: Get dependencies for example
39-
run: flutter pub get
40-
working-directory: example
41-
- name: Lint using flutter analyze
42-
run: flutter analyze .
43-
44-
test:
45-
name: Run tests.
46-
runs-on: ubuntu-latest
4750

48-
steps:
49-
- name: Checkout code
50-
uses: actions/checkout@v4
51-
- name: Flutter Action
52-
uses: subosito/flutter-action@v2
53-
- name: Run flutter test
54-
run: |
55-
flutter pub get
56-
flutter test
51+
- name: ✨ Check Formatting
52+
run: dart format --set-exit-if-changed lib
53+
54+
- name: 🕵️ Analyze
55+
run: flutter analyze lib
56+
57+
- name: 🧪 Run Tests
58+
run: flutter test --no-pub --coverage --test-randomize-ordering-seed random
59+
60+
- name: 📁 Upload coverage to Codecov
61+
uses: codecov/codecov-action@v5

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [1.9.2]
2+
* Fixed broken Table of Contents links in `README.md`, take two.
3+
4+
## [1.9.1+1]
5+
* Fixed broken Table of Contents links in `README.md`.
6+
7+
## [1.9.1]
8+
* [#872](https://github.com/fluttercommunity/chewie/pull/872): feat: Add showSubtitles flag to control subtitles (#648). Thanks [floodoo](https://github.com/floodoo).
9+
* [#890](https://github.com/fluttercommunity/chewie/pull/890): Fix issue 888. Thanks [diegotori](https://github.com/diegotori).
10+
* **IMPORTANT**: Relaxed the minimum supported Flutter version to `3.24`.
11+
From now on, this library will make a best effort to support the latest `N-1` Flutter version at the minimum.
12+
113
## [1.9.0]
214
* **BREAKING CHANGE**: Library now requires at least Flutter version `3.27.0`.
315

README.md

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,53 @@
88

99
The video player for Flutter with a heart of gold.
1010

11-
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!
11+
The [`video_player`](https://pub.dartlang.org/packages/video_player) plugin provides low-level
12+
access to video playback.
1213

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

15-
| MaterialControls | MaterialDesktopControls |
16-
| :--------------: | :---------------------: |
17-
| ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialControls.png) | ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialDesktopControls.png) |
16+
## Table of Contents
17+
1. 🚨 [IMPORTANT!!! (READ THIS FIRST)](#-important-read-this-first)
18+
2. 🔀 [Flutter Version Compatibility](#-flutter-version-compatibility)
19+
3. 🖼️ [Preview](#%EF%B8%8F-preview)
20+
4. ⬇️ [Installation](#%EF%B8%8F-installation)
21+
5. 🕹️ [Using it](#%EF%B8%8F-using-it)
22+
6. ⚙️ [Options](#%EF%B8%8F-options)
23+
7. 🔡 [Subtitles](#-subtitles)
24+
8. 🧪 [Example](#-example)
25+
9.[Migrating from Chewie < 0.9.0](#-migrating-from-chewie--090)
26+
10. 🗺️ [Roadmap](#%EF%B8%8F-roadmap)
27+
11. 📱 [iOS warning](#-ios-warning-)
28+
29+
30+
## 🚨 IMPORTANT!!! (READ THIS FIRST)
31+
This library is __NOT__ responsible for any issues caused by `video_player`, since it's merely a UI
32+
layer on top of it.
33+
34+
In other words, if you see any `PlatformException`s being thrown in your app due to video playback,
35+
they are exclusive to the `video_player` library.
36+
37+
Instead, please raise an issue related to it with the [Flutter Team](https://github.com/flutter/flutter/issues/new/choose).
38+
39+
## 🔀 Flutter Version Compatibility
40+
41+
This library will at the very least make a solid effort to support the second most recent version
42+
of Flutter released. In other words, it will adopt `N-1` version support at
43+
the bare minimum.
44+
45+
However, this cannot be guaranteed due to major changes between Flutter versions. Should that occur,
46+
future updates will be released as major or minor versions as needed.
47+
48+
## 🖼️ Preview
49+
50+
| MaterialControls | MaterialDesktopControls |
51+
|:-------------------------------------------------------------------------------:|:--------------------------------------------------------------------------------------:|
52+
| ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialControls.png) | ![](https://github.com/brianegan/chewie/raw/master/assets/MaterialDesktopControls.png) |
1853

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

22-
## Installation
57+
## ⬇️ Installation
2358

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

@@ -29,7 +64,7 @@ dependencies:
2964
video_player: <latest_version>
3065
```
3166
32-
## Using it
67+
## 🕹️ Using it
3368
3469
```dart
3570
import 'package:chewie/chewie.dart';
@@ -61,7 +96,7 @@ void dispose() {
6196
}
6297
```
6398

64-
## Options
99+
## ⚙️ Options
65100

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

@@ -127,13 +162,19 @@ optionsTranslation: OptionsTranslation(
127162
),
128163
```
129164

130-
## Subtitles
165+
## 🔡 Subtitles
166+
167+
> Since version 1.1.0, Chewie supports subtitles.
168+
169+
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.
170+
171+
### Showing Subtitles by Default
131172

132-
> Since version 1.1.0 chewie supports subtitles. Here you can see how to use them.
173+
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`.
133174

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

136-
Add subtitles to your `ChewieController` like the following example:
177+
Here’s an example of how to add subtitles to your `ChewieController`:
137178

138179
```dart
139180
ChewieController(
@@ -151,9 +192,10 @@ ChewieController(
151192
index: 1,
152193
start: const Duration(seconds: 10),
153194
end: const Duration(seconds: 20),
154-
text: 'Whats up? :)',
195+
text: 'What’s up? :)',
155196
),
156197
]),
198+
showSubtitles: true, // Automatically display subtitles
157199
subtitleBuilder: (context, subtitle) => Container(
158200
padding: const EdgeInsets.all(10.0),
159201
child: Text(
@@ -164,9 +206,16 @@ ChewieController(
164206
);
165207
```
166208

167-
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.
209+
### Subtitle Structure
168210

169-
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:
211+
The `Subtitle` model contains the following key attributes:
212+
213+
- **`index`**: A unique identifier for the subtitle, useful for database integration.
214+
- **`start`**: The starting point of the subtitle, defined as a `Duration`.
215+
- **`end`**: The ending point of the subtitle, defined as a `Duration`.
216+
- **`text`**: The subtitle text that will be displayed.
217+
218+
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:
170219

171220
```dart
172221
Subtitle(
@@ -177,11 +226,15 @@ Subtitle(
177226
),
178227
```
179228

180-
## Example
229+
### Customizing Subtitles
230+
231+
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.
232+
233+
## 🧪 Example
181234

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

184-
## Migrating from Chewie < 0.9.0
237+
## Migrating from Chewie < 0.9.0
185238

186239
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.
187240

@@ -207,7 +260,7 @@ final playerWidget = Chewie(
207260
);
208261
```
209262

210-
## Roadmap
263+
## 🗺️ Roadmap
211264

212265
- [x] MaterialUI
213266
- [x] MaterialDesktopUI
@@ -233,7 +286,7 @@ final playerWidget = Chewie(
233286
- [ ] Screen-Mirroring / Casting (Google Chromecast)
234287

235288

236-
## iOS warning
289+
## 📱 iOS warning
237290

238291
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`
239292
Please refer to this [issue](https://github.com/flutter/flutter/issues/14647).

example/lib/app/app.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class _ChewieDemoState extends State<ChewieDemo> {
4949
// "https://assets.mixkit.co/videos/preview/mixkit-spinning-around-the-earth-29351-large.mp4",
5050
// "https://assets.mixkit.co/videos/preview/mixkit-daytime-city-traffic-aerial-view-56-large.mp4",
5151
// "https://assets.mixkit.co/videos/preview/mixkit-a-girl-blowing-a-bubble-gum-at-an-amusement-park-1226-large.mp4"
52+
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
53+
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4",
54+
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerBlazes.mp4",
5255
];
5356

5457
Future<void> initializePlayer() async {
@@ -131,6 +134,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
131134
];
132135
},
133136
subtitle: Subtitles(subtitles),
137+
showSubtitles: true,
134138
subtitleBuilder: (context, dynamic subtitle) => Container(
135139
padding: const EdgeInsets.all(10.0),
136140
child: subtitle is InlineSpan

lib/src/chewie_player.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class ChewieController extends ChangeNotifier {
302302
this.zoomAndPan = false,
303303
this.maxScale = 2.5,
304304
this.subtitle,
305+
this.showSubtitles = false,
305306
this.subtitleBuilder,
306307
this.customControls,
307308
this.errorBuilder,
@@ -353,6 +354,7 @@ class ChewieController extends ChangeNotifier {
353354
bool? zoomAndPan,
354355
double? maxScale,
355356
Subtitles? subtitle,
357+
bool? showSubtitles,
356358
Widget Function(BuildContext, dynamic)? subtitleBuilder,
357359
Widget? customControls,
358360
WidgetBuilder? bufferingBuilder,
@@ -406,6 +408,7 @@ class ChewieController extends ChangeNotifier {
406408
optionsBuilder: optionsBuilder ?? this.optionsBuilder,
407409
additionalOptions: additionalOptions ?? this.additionalOptions,
408410
showControls: showControls ?? this.showControls,
411+
showSubtitles: showSubtitles ?? this.showSubtitles,
409412
subtitle: subtitle ?? this.subtitle,
410413
subtitleBuilder: subtitleBuilder ?? this.subtitleBuilder,
411414
customControls: customControls ?? this.customControls,
@@ -469,6 +472,12 @@ class ChewieController extends ChangeNotifier {
469472
/// Add a List of Subtitles here in `Subtitles.subtitle`
470473
Subtitles? subtitle;
471474

475+
/// Determines whether subtitles should be shown by default when the video starts.
476+
///
477+
/// If set to `true`, subtitles will be displayed automatically when the video
478+
/// begins playing. If set to `false`, subtitles will be hidden by default.
479+
bool showSubtitles;
480+
472481
/// The controller for the video you want to play
473482
final VideoPlayerController videoPlayerController;
474483

lib/src/cupertino/cupertino_controls.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ class _CupertinoControlsState extends State<CupertinoControls>
641641
}
642642

643643
Future<void> _initialize() async {
644-
_subtitleOn = chewieController.subtitle?.isNotEmpty ?? false;
644+
chewieController.showSubtitles &&
645+
(chewieController.subtitle?.isNotEmpty ?? false);
645646
controller.addListener(_updateState);
646647

647648
_updateState();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import 'package:flutter/material.dart';
2+
3+
//ignore_for_file: deprecated_member_use
4+
extension ColorCompatExtensions on Color {
5+
/// Returns a new color that matches this color with the given opacity.
6+
///
7+
/// This is a compatibility layer that ensures compatibility with Flutter
8+
/// versions below 3.27. In Flutter 3.27 and later, `Color.withOpacity`
9+
/// has been deprecated in favor of `Color.withValues`.
10+
///
11+
/// This method bridges the gap by providing a consistent way to adjust
12+
/// the opacity of a color across different Flutter versions.
13+
///
14+
/// **Important:** Once the minimum supported Flutter version is bumped
15+
/// to 3.27 or higher, this method should be removed and replaced with
16+
/// `withValues(alpha: opacity)`.
17+
///
18+
/// See also:
19+
/// * [Color.withOpacity], which is deprecated in Flutter 3.27 and later.
20+
/// * [Color.withValues], the recommended replacement for `withOpacity`.
21+
Color withOpacityCompat(double opacity) {
22+
// Compatibility layer that uses the legacy withOpacity method, while
23+
// ignoring the deprecation for now (in order to guarantee N-1 minimum
24+
// version compatibility).
25+
// Once it's removed from a future update, we'll have to replace uses of
26+
// this method with withValues(alpha: opacity).
27+
// TODO: Replace this bridge method once the above holds true.
28+
return withOpacity(opacity);
29+
}
30+
}

0 commit comments

Comments
 (0)