import 'package:better_player/better_player.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:teso/Classes/Firebase/Posts.dart'; import 'package:teso/util/consts.dart'; abstract class VideoControllerService { Future getControllerForVideo(FBPosts video); } class CachedVideoControllerService extends VideoControllerService { // ignore: unused_field final BaseCacheManager _cacheManager; CachedVideoControllerService(this._cacheManager) : assert(_cacheManager != null); @override Future getControllerForVideo(FBPosts video) async { try { BetterPlayerDataSource betterPlayerDataSource = BetterPlayerDataSource( BetterPlayerDataSourceType.network, "https://stream.mux.com/${video.playbackID}.m3u8", videoFormat: BetterPlayerVideoFormat.hls, cacheConfiguration: BetterPlayerCacheConfiguration( useCache: true, ), ); return BetterPlayerController( BetterPlayerConfiguration( autoPlay: true, aspectRatio: double.tryParse(video.aspect), looping: true, fit: double.parse(video.aspect) < 1 ? BoxFit.fitHeight : BoxFit.fitWidth, showPlaceholderUntilPlay: true, placeholder: Container( child: Center( child: CachedNetworkImage( imageUrl: tesoPostThumb(video.playbackID), imageBuilder: (context, imageProvider) => FadeInImage( width: double.infinity, fit: BoxFit.fill, image: imageProvider, placeholder: AssetImage("assets/images/blank.jpg"), ), errorWidget: (context, url, error) => Image.asset("assets/images/blank.jpg"), ), ), ), controlsConfiguration: BetterPlayerControlsConfiguration( showControls: false, ), autoDispose: true, ), betterPlayerDataSource: betterPlayerDataSource, ); } catch (e) { // return BetterPlayerController.network(tesoStreaming + "pd/" + video.path); return null; } } }