Skip to content

Commit

Permalink
Feature/may changes (jhomlala#472)
Browse files Browse the repository at this point in the history
* * Added check in seek method to handle scenario when video wasn't ready to play.

* Added setupDataSourceList in BetterPlayerPlaylistController

* Fixed stalled issue in iOS

* Added pause before dispose in iOS

* Added pause before dispose in iOS

* * Added bufferedStart, bufferedUpdate, bufferedEnd events.

* Fixed full screen dismissed when new data source loaded.

* Fixed full screen dismissed when new data source loaded.

* Added forget option for VisibilityDetectorController

* Updated version & formatting

* Formatting
  • Loading branch information
jhomlala authored May 8, 2021
1 parent 82f9317 commit 2ea18d8
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 7 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.0.66
* Added check in seek method to handle scenario when video wasn't ready to play.
* Added setupDataSourceList in BetterPlayerPlaylistController.
* Fixed playback stalled issue in iOS.
* Added pause on iOS dispose call.
* Added bufferedStart, bufferedUpdate, bufferedEnd events.
* Fixed full screen dismissed when new data source loaded.
* Added forget option for VisibilityDetectorController (by https://github.com/ChopinDavid).
* Added vietnamese translations (by https://github.com/thanhvn-57).

## 0.0.65
* Refactored Android notification image selection.
* Added headers parameter in BetterPlayerSubtitlesSource. Headers is an optional parameter.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.65
better_player: ^0.0.66
```
2. Install it
Expand Down
16 changes: 16 additions & 0 deletions example/lib/pages/playlist_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ class _PlaylistPageState extends State<PlaylistPage> {
},
child: Text("Pause current video with BetterPlayerController"),
),
ElevatedButton(
onPressed: () {
var list = [
BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
Constants.bugBuckBunnyVideoUrl,
placeholder: Image.network(
Constants.catImageUrl,
fit: BoxFit.cover,
),
)
];
_betterPlayerPlaylistController?.setupDataSourceList(list);
},
child: Text("Setup new data source list"),
),
]);
}
},
Expand Down
17 changes: 15 additions & 2 deletions ios/Classes/FLTBetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ @interface FLTBetterPlayer : NSObject <FlutterTexture, FlutterStreamHandler, AVP
@property(nonatomic) bool _pictureInPicture;
@property(nonatomic) bool _observersAdded;
@property(nonatomic) int stalledCount;
@property(nonatomic) bool isStalledCheckStarted;
@property(nonatomic) float playerRate;
- (void)play;
- (void)pause;
Expand Down Expand Up @@ -319,6 +320,7 @@ - (void)setDataSourceURL:(NSURL*)url withKey:(NSString*)key withHeaders:(NSDicti
- (void)setDataSourcePlayerItem:(AVPlayerItem*)item withKey:(NSString*)key{
_key = key;
_stalledCount = 0;
_isStalledCheckStarted = false;
_playerRate = 1;
[_player replaceCurrentItemWithPlayerItem:item];

Expand Down Expand Up @@ -356,19 +358,28 @@ - (void)setDataSourcePlayerItem:(AVPlayerItem*)item withKey:(NSString*)key{
}

-(void)handleStalled {
if (_isStalledCheckStarted){
return;
}
_isStalledCheckStarted = true;
[self startStalledCheck];
}

-(void)startStalledCheck{
if (_player.currentItem.playbackLikelyToKeepUp ||
[self availableDuration] - CMTimeGetSeconds(_player.currentItem.currentTime) > 10.0) {
[self play];
} else {
_stalledCount++;
if (_stalledCount > 5){
if (_stalledCount > 60){
_eventSink([FlutterError
errorWithCode:@"VideoError"
message:@"Failed to load video: playback stalled"
details:nil]);
return;
}
[self performSelector:@selector(handleStalled) withObject:nil afterDelay:1];
[self performSelector:@selector(startStalledCheck) withObject:nil afterDelay:1];

}
}

Expand Down Expand Up @@ -535,6 +546,7 @@ - (void)onReadyToPlay {

- (void)play {
_stalledCount = 0;
_isStalledCheckStarted = false;
_isPlaying = true;
[self updatePlayingState];
}
Expand Down Expand Up @@ -860,6 +872,7 @@ - (void)disposeSansEventChannel {
}

- (void)dispose {
[self pause];
[self disposeSansEventChannel];
[_eventChannel setStreamHandler:nil];
[self disablePictureInPicture];
Expand Down
5 changes: 4 additions & 1 deletion lib/src/configuration/better_player_event_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ enum BetterPlayerEventType {
changedResolution,
pipStart,
pipStop,
setupDataSource
setupDataSource,
bufferingStart,
bufferingUpdate,
bufferingEnd,
}
19 changes: 18 additions & 1 deletion lib/src/core/better_player_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class BetterPlayerController {
static const String _volumeParameter = "volume";
static const String _speedParameter = "speed";
static const String _dataSourceParameter = "dataSource";
static const String _bufferedParameter = "buffered";
static const String _hlsExtension = "m3u8";
static const String _authorizationHeader = "Authorization";

Expand Down Expand Up @@ -457,7 +458,7 @@ class BetterPlayerController {

final fullScreenByDefault = betterPlayerConfiguration.fullScreenByDefault;
if (betterPlayerConfiguration.autoPlay) {
if (fullScreenByDefault) {
if (fullScreenByDefault && !isFullScreen) {
enterFullScreen();
}
if (_isAutomaticPlayPauseHandled()) {
Expand Down Expand Up @@ -552,6 +553,10 @@ class BetterPlayerController {
if (videoPlayerController == null) {
throw StateError("The data source has not been initialized");
}
if (videoPlayerController?.value.duration == null) {
throw StateError("The video has not been initialized yet.");
}

await videoPlayerController!.seekTo(moment);

_postEvent(BetterPlayerEvent(BetterPlayerEventType.seekTo,
Expand Down Expand Up @@ -1006,6 +1011,18 @@ class BetterPlayerController {
),
);
break;
case VideoEventType.bufferingStart:
_postEvent(BetterPlayerEvent(BetterPlayerEventType.bufferingStart));
break;
case VideoEventType.bufferingUpdate:
_postEvent(BetterPlayerEvent(BetterPlayerEventType.bufferingUpdate,
parameters: <String, dynamic>{
_bufferedParameter: event.buffered,
}));
break;
case VideoEventType.bufferingEnd:
_postEvent(BetterPlayerEvent(BetterPlayerEventType.bufferingEnd));
break;
default:

///TODO: Handle when needed
Expand Down
11 changes: 10 additions & 1 deletion lib/src/playlist/better_player_playlist_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BetterPlayerPlaylistController {

///Initialize controller and listeners.
void _setup() {
_betterPlayerController = BetterPlayerController(
_betterPlayerController ??= BetterPlayerController(
betterPlayerConfiguration,
betterPlayerPlaylistConfiguration: betterPlayerPlaylistConfiguration,
);
Expand All @@ -61,6 +61,15 @@ class BetterPlayerPlaylistController {
});
}

/// Setup new data source list. Pauses currently played video and init new data
/// source list. Previous data source list will be removed.
void setupDataSourceList(List<BetterPlayerDataSource> dataSourceList) {
_betterPlayerController?.pause();
_betterPlayerDataSourceList.clear();
_betterPlayerDataSourceList.addAll(dataSourceList);
_setup();
}

///Handle video change signal from BetterPlayerController. Setup new data
///source based on configuration.
void _onVideoChange() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: better_player
description: Advanced video player based on video_player and Chewie. It's solves many typical use cases and it's easy to run.
version: 0.0.65
version: 0.0.66
authors:
- Jakub Homlala <jhomlala@gmail.com>
homepage: https://github.com/jhomlala/betterplayer
Expand Down

0 comments on commit 2ea18d8

Please sign in to comment.