Skip to content

Commit

Permalink
Feature/player notifications (jhomlala#181)
Browse files Browse the repository at this point in the history
* setControlsEnabled implementation

* Updated documentation

* Fixed video list widget buttons not rendering correctly in small resolutions

* Fixed video list widget buttons not rendering correctly in small resolutions

* Added setOverriddenAspectRatio, added example for overriding aspect ratio

* Fixed deviceOrientationsOnFullScreen for iOS

* iOS player notifications implementation

* Player notification implementation

* Player notification implementation

* iOS player notifications implementation

* iOS player notifications implementation

* Android player notifications implementation

* General player notifications implementation

* Android notification image

* iOS notification handling

* iOS notification handling

* iOS notification handling

* iOS notification handling

* Android notification handling

* Android notification handling

* Android notification handling

* Notification handling

* Notification handling

* Notification handling

* Merge fixes, readme update, changelog update

* Added media file

* General refactor

* Update README.md

* Update README.md

* Update README.md

* PR refactor
  • Loading branch information
jhomlala authored Dec 27, 2020
1 parent c512ae1 commit 8514f93
Show file tree
Hide file tree
Showing 32 changed files with 1,489 additions and 671 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.0.38
* Added support for player notifications
* Added handleLifecycle to BetterPlayerConfiguration
* Added notificationConfiguration to BetterPlayerDataSource

## 0.0.37
* Added setControlsEnabled to BetterPlayerController
* Fixed example video list widget buttons not rendering correctly in small resolutions
Expand Down
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is
✔️ HLS support (track, subtitles selection)
✔️ Alternative resolution support
✔️ Cache support
✔️ ... and much more!
✔️ Notifications support
✔️ ... and much more!


## Install
Expand All @@ -34,7 +35,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.37
better_player: ^0.0.38
```
2. Install it
Expand Down Expand Up @@ -727,6 +728,56 @@ only for normal videos (non-hls) to setup different qualities of the original vi
"https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4"
});
```
### Setup player notification
<table>
<tr>
<td>
<img width="250px" src="https://raw.githubusercontent.com/jhomlala/betterplayer/feature/player_notifications/media/android_notification.png">
</td>
<td>
<img width="250px" src="https://raw.githubusercontent.com/jhomlala/betterplayer/feature/player_notifications/media/ios_notification.png">
</td>
<td>
</tr>
</table>

To setup player notification use notificationConfiguration in BetterPlayerDataSource.

```dart
BetterPlayerDataSource dataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.NETWORK,
Constants.elephantDreamVideoUrl,
notificationConfiguration: BetterPlayerNotificationConfiguration(
showNotification: true,
title: "Elephant dream",
author: "Some author",
imageUrl:"https://upload.wikimedia.org/wikipedia/commons/thumb/3/37/African_Bush_Elephant.jpg/1200px-African_Bush_Elephant.jpg",
),
);
```

There are 3 majors parameters here:
title - name of the resource, shown in first line
author - author of the resource, shown in second line
imageUrl - image of the resource (optional). Can be both link to external image or internal file.

If showNotification is set as true and no title and author is provided, then empty notification will be
displayed.

User can control the player with notification buttons (i.e. play/pause, seek). When notification feature
is used when there are more players at the same time, then last player will be used. Notification will
be shown after play for the first time.

To play resource after leaving the app, set handleLifecycle as false in your BetterPlayerConfiguration.

Important note for android:
You need to add special service in android native code. Service will simply destroy all remaining notifications.
This service need to be used to handle situation when app is killed without proper player destroying.
Check BetterPlayerService in example project to see how to add this service to your app.
https://github.com/jhomlala/betterplayer/blob/feature/player_notifications/example/android/app/src/main/kotlin/com/jhomlala/better_player_example/BetterPlayerService.kt

Here is an example of player with notification: https://github.com/jhomlala/betterplayer/blob/feature/player_notifications/example/lib/pages/notification_player_page.dart


### Add custom element to overflow menu
You can use BetterPlayerControlsConfiguration to add custom element to the overflow menu:
Expand Down
32 changes: 7 additions & 25 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,13 @@ android {
implementation 'com.google.android.exoplayer:exoplayer-hls:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.9.6'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.6'
implementation "android.arch.lifecycle:runtime:1.1.1"
implementation "android.arch.lifecycle:common:1.1.1"
implementation "android.arch.lifecycle:common-java8:1.1.1"
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}
}

// TODO(mklim): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "1.1.1"
compileOnly "android.arch.lifecycle:runtime:$lifecycle_version"
compileOnly "android.arch.lifecycle:common:$lifecycle_version"
compileOnly "android.arch.lifecycle:common-java8:$lifecycle_version"
}
}
}
}

3 changes: 3 additions & 0 deletions android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
Loading

0 comments on commit 8514f93

Please sign in to comment.