You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.3 KiB
68 lines
2.3 KiB
3 years ago
|
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<BetterPlayerController> getControllerForVideo(FBPosts video);
|
||
|
}
|
||
|
|
||
|
class CachedVideoControllerService extends VideoControllerService {
|
||
|
// ignore: unused_field
|
||
|
final BaseCacheManager _cacheManager;
|
||
|
|
||
|
CachedVideoControllerService(this._cacheManager)
|
||
|
: assert(_cacheManager != null);
|
||
|
|
||
|
@override
|
||
|
Future<BetterPlayerController> 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;
|
||
|
}
|
||
|
}
|
||
|
}
|