Skip to content

Commit

Permalink
fix(Trailer-Screen): Fixed trailer not loading
Browse files Browse the repository at this point in the history
Signed-off-by: arafaysaleem <a.rafaysaleem@gmail.com>
  • Loading branch information
arafaysaleem committed Jan 12, 2022
1 parent 1e726c3 commit c779daf
Showing 1 changed file with 32 additions and 28 deletions.
60 changes: 32 additions & 28 deletions lib/views/screens/trailer_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TrailerScreen extends StatefulHookConsumerWidget {

class _TrailerScreenState extends ConsumerState<TrailerScreen> {
late final BetterPlayerController _betterPlayerController;
bool isInitialized = false;

final _controlsConfiguration = const BetterPlayerControlsConfiguration(
overflowModalTextColor: Constants.textGreyColor,
Expand All @@ -36,34 +37,37 @@ class _TrailerScreenState extends ConsumerState<TrailerScreen> {
);

@override
void initState() {
super.initState();
final betterPlayerConfiguration = BetterPlayerConfiguration(
aspectRatio: 4 / 3,
fullScreenAspectRatio: 16 / 9,
looping: false,
autoPlay: true,
fit: BoxFit.cover,
allowedScreenSleep: false,
deviceOrientationsAfterFullScreen: [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
systemOverlaysAfterFullScreen: [SystemUiOverlay.top],
fullScreenByDefault: true,
autoDetectFullscreenDeviceOrientation: true,
controlsConfiguration: _controlsConfiguration,
errorBuilder: _buildErrorWidget,
);
final trailerUrl = ref.watch(selectedMovieProvider.select((value) => value.trailerUrl));
final betterPlayerDataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
trailerUrl,
);
_betterPlayerController = BetterPlayerController(
betterPlayerConfiguration,
betterPlayerDataSource: betterPlayerDataSource,
);
void didChangeDependencies() {
super.didChangeDependencies();
if (!isInitialized) {
final betterPlayerConfiguration = BetterPlayerConfiguration(
aspectRatio: 4 / 3,
fullScreenAspectRatio: 16 / 9,
looping: false,
autoPlay: true,
fit: BoxFit.cover,
allowedScreenSleep: false,
deviceOrientationsAfterFullScreen: [
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
],
systemOverlaysAfterFullScreen: [SystemUiOverlay.top],
fullScreenByDefault: true,
autoDetectFullscreenDeviceOrientation: true,
controlsConfiguration: _controlsConfiguration,
errorBuilder: _buildErrorWidget,
);
final trailerUrl = ref.watch(selectedMovieProvider.select((value) => value.trailerUrl));
final betterPlayerDataSource = BetterPlayerDataSource(
BetterPlayerDataSourceType.network,
trailerUrl,
);
_betterPlayerController = BetterPlayerController(
betterPlayerConfiguration,
betterPlayerDataSource: betterPlayerDataSource,
);
isInitialized = true;
}
}

@override
Expand Down

0 comments on commit c779daf

Please sign in to comment.