Skip to content

Commit

Permalink
Added list player controller
Browse files Browse the repository at this point in the history
  • Loading branch information
jhomlalabsg committed Jun 11, 2020
1 parent b11e5da commit 2abab0e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
27 changes: 27 additions & 0 deletions example/lib/video_list/video_list_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ class VideoListWidget extends StatefulWidget {

class _VideoListWidgetState extends State<VideoListWidget> {
VideoListData get videoListData => widget.videoListData;
BetterPlayerConfiguration betterPlayerConfiguration;
BetterPlayerListVideoPlayerController controller;

@override
void initState() {
super.initState();
controller = BetterPlayerListVideoPlayerController();
betterPlayerConfiguration = BetterPlayerConfiguration(autoPlay: false);
}

@override
Expand All @@ -40,6 +44,7 @@ class _VideoListWidgetState extends State<VideoListWidget> {
configuration: BetterPlayerConfiguration(autoPlay: false),
key: Key(videoListData.hashCode.toString()),
playFraction: 0.8,
controller: controller,
),
aspectRatio: 16 / 9),
Padding(
Expand All @@ -52,6 +57,28 @@ class _VideoListWidgetState extends State<VideoListWidget> {
"lives? 70's special effects, legendary score, and trademark "
"humor set this classic apart."),
),
Row(children: [
RaisedButton(
child: Text("Play"),
onPressed: () {
controller.play();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Pause"),
onPressed: () {
controller.pause();
},
),
const SizedBox(width: 8),
RaisedButton(
child: Text("Set max volume"),
onPressed: () {
controller.setVolume(100);
},
),
])
],
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/better_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export 'src/playlist/better_player_playlist_configuration.dart';
export 'src/subtitles/better_player_subtitles_configuration.dart';
export 'src/controls/better_player_controls_configuration.dart';
export 'src/list/better_player_list_video_player.dart';
export 'src/list/better_player_list_video_player_controller.dart';
export 'src/subtitles/better_player_subtitles_source.dart';
export 'src/subtitles/better_player_subtitles_source_type.dart';
8 changes: 8 additions & 0 deletions lib/src/list/better_player_list_video_player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:better_player/better_player.dart';
import 'package:better_player/src/configuration/better_player_configuration.dart';
import 'package:better_player/src/configuration/better_player_data_source.dart';
import 'package:better_player/src/list/better_player_list_video_player_controller.dart';
import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';

Expand All @@ -22,11 +23,14 @@ class BetterPlayerListVideoPlayer extends StatefulWidget {
///Flag to determine if video should be auto paused
final bool autoPause;

final BetterPlayerListVideoPlayerController controller;

const BetterPlayerListVideoPlayer(this.dataSource,
{this.configuration = const BetterPlayerConfiguration(),
this.playFraction = 0.6,
this.autoPlay = true,
this.autoPause = true,
this.controller,
Key key})
: assert(dataSource != null, "Data source can't be null"),
assert(configuration != null, "Configuration can't be null"),
Expand Down Expand Up @@ -54,6 +58,10 @@ class _BetterPlayerListVideoPlayerState
widget.configuration,
betterPlayerDataSource: widget.dataSource,
);
if (widget.controller != null) {
widget.controller.setBetterPlayerController(_betterPlayerController);
}

super.initState();
}

Expand Down
23 changes: 23 additions & 0 deletions lib/src/list/better_player_list_video_player_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:better_player/better_player.dart';

class BetterPlayerListVideoPlayerController{
BetterPlayerController _betterPlayerController;

void setVolume(double volume){
assert(volume != null, "Volume can't be null");
_betterPlayerController?.setVolume(volume);
}

void pause(){
_betterPlayerController?.pause();
}

void play(){
_betterPlayerController?.play();
}

void setBetterPlayerController(BetterPlayerController betterPlayerController){
_betterPlayerController = betterPlayerController;
}

}

0 comments on commit 2abab0e

Please sign in to comment.