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.
66 lines
2.3 KiB
66 lines
2.3 KiB
import 'package:better_player/better_player.dart';
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
|
import 'package:teso/Classes/API%20Clasess/Post.dart';
|
|
import 'package:teso/util/consts.dart';
|
|
|
|
abstract class VideoControllerService {
|
|
Future<BetterPlayerController> getControllerForVideo(Post video);
|
|
}
|
|
|
|
class CachedVideoControllerService extends VideoControllerService {
|
|
// ignore: unused_field
|
|
final BaseCacheManager _cacheManager;
|
|
|
|
CachedVideoControllerService(this._cacheManager)
|
|
: assert(_cacheManager != null);
|
|
|
|
@override
|
|
Future<BetterPlayerController> getControllerForVideo(Post 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: BoxFit.fill,
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|