mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-24 22:42:33 +01:00
chore: Fix videoplayer in stories
This commit is contained in:
parent
b571f84991
commit
bc07cc28e0
@ -181,7 +181,7 @@ class StoryPageController extends State<StoryPage> {
|
||||
}
|
||||
});
|
||||
final max = _videoPlayerController?.value.duration ?? maxProgress;
|
||||
if (progress > max) {
|
||||
if (progress >= max) {
|
||||
skip();
|
||||
}
|
||||
});
|
||||
@ -196,14 +196,26 @@ class StoryPageController extends State<StoryPage> {
|
||||
|
||||
String get roomId => VRouter.of(context).pathParameters['roomid'] ?? '';
|
||||
|
||||
Future<VideoPlayerController>? loadVideoControllerFuture;
|
||||
|
||||
Future<VideoPlayerController> loadVideoController(Event event) async {
|
||||
final matrixFile = await event.downloadAndDecryptAttachment();
|
||||
final tmpDirectory = await getTemporaryDirectory();
|
||||
final file = File(tmpDirectory.path + matrixFile.name);
|
||||
final videoPlayerController = VideoPlayerController.file(file);
|
||||
await videoPlayerController.initialize();
|
||||
videoPlayerController.play();
|
||||
return videoPlayerController;
|
||||
try {
|
||||
final matrixFile = await event.downloadAndDecryptAttachment();
|
||||
final tmpDirectory = await getTemporaryDirectory();
|
||||
final fileName =
|
||||
event.content.tryGet<String>('filename') ?? 'unknown_story_video.mp4';
|
||||
final file = File(tmpDirectory.path + '/' + fileName);
|
||||
await file.writeAsBytes(matrixFile.bytes);
|
||||
final videoPlayerController =
|
||||
_videoPlayerController = VideoPlayerController.file(file);
|
||||
await videoPlayerController.initialize();
|
||||
await videoPlayerController.play();
|
||||
return videoPlayerController;
|
||||
} catch (e, s) {
|
||||
Logs().w('Unable to load video story. Try again...', e, s);
|
||||
await Future.delayed(const Duration(seconds: 3));
|
||||
return loadVideoController(event);
|
||||
}
|
||||
}
|
||||
|
||||
void skip() {
|
||||
@ -212,6 +224,9 @@ class StoryPageController extends State<StoryPage> {
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_videoPlayerController?.dispose();
|
||||
_videoPlayerController = null;
|
||||
loadVideoControllerFuture = null;
|
||||
index++;
|
||||
});
|
||||
_restartTimer();
|
||||
@ -222,6 +237,12 @@ class StoryPageController extends State<StoryPage> {
|
||||
|
||||
bool isHold = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_videoPlayerController?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void hold([_]) {
|
||||
_holdedAt = DateTime.now();
|
||||
if (loadingMode) return;
|
||||
|
@ -160,7 +160,8 @@ class StoryView extends StatelessWidget {
|
||||
if (event.messageType == MessageTypes.Video &&
|
||||
PlatformInfos.isMobile)
|
||||
FutureBuilder<VideoPlayerController>(
|
||||
future: controller.loadVideoController(event),
|
||||
future: controller.loadVideoControllerFuture ??=
|
||||
controller.loadVideoController(event),
|
||||
builder: (context, snapshot) {
|
||||
final videoPlayerController = snapshot.data;
|
||||
if (videoPlayerController == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user