mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 23:09:35 +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;
|
final max = _videoPlayerController?.value.duration ?? maxProgress;
|
||||||
if (progress > max) {
|
if (progress >= max) {
|
||||||
skip();
|
skip();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -196,14 +196,26 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
|
|
||||||
String get roomId => VRouter.of(context).pathParameters['roomid'] ?? '';
|
String get roomId => VRouter.of(context).pathParameters['roomid'] ?? '';
|
||||||
|
|
||||||
|
Future<VideoPlayerController>? loadVideoControllerFuture;
|
||||||
|
|
||||||
Future<VideoPlayerController> loadVideoController(Event event) async {
|
Future<VideoPlayerController> loadVideoController(Event event) async {
|
||||||
final matrixFile = await event.downloadAndDecryptAttachment();
|
try {
|
||||||
final tmpDirectory = await getTemporaryDirectory();
|
final matrixFile = await event.downloadAndDecryptAttachment();
|
||||||
final file = File(tmpDirectory.path + matrixFile.name);
|
final tmpDirectory = await getTemporaryDirectory();
|
||||||
final videoPlayerController = VideoPlayerController.file(file);
|
final fileName =
|
||||||
await videoPlayerController.initialize();
|
event.content.tryGet<String>('filename') ?? 'unknown_story_video.mp4';
|
||||||
videoPlayerController.play();
|
final file = File(tmpDirectory.path + '/' + fileName);
|
||||||
return videoPlayerController;
|
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() {
|
void skip() {
|
||||||
@ -212,6 +224,9 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
|
_videoPlayerController?.dispose();
|
||||||
|
_videoPlayerController = null;
|
||||||
|
loadVideoControllerFuture = null;
|
||||||
index++;
|
index++;
|
||||||
});
|
});
|
||||||
_restartTimer();
|
_restartTimer();
|
||||||
@ -222,6 +237,12 @@ class StoryPageController extends State<StoryPage> {
|
|||||||
|
|
||||||
bool isHold = false;
|
bool isHold = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_videoPlayerController?.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void hold([_]) {
|
void hold([_]) {
|
||||||
_holdedAt = DateTime.now();
|
_holdedAt = DateTime.now();
|
||||||
if (loadingMode) return;
|
if (loadingMode) return;
|
||||||
|
@ -160,7 +160,8 @@ class StoryView extends StatelessWidget {
|
|||||||
if (event.messageType == MessageTypes.Video &&
|
if (event.messageType == MessageTypes.Video &&
|
||||||
PlatformInfos.isMobile)
|
PlatformInfos.isMobile)
|
||||||
FutureBuilder<VideoPlayerController>(
|
FutureBuilder<VideoPlayerController>(
|
||||||
future: controller.loadVideoController(event),
|
future: controller.loadVideoControllerFuture ??=
|
||||||
|
controller.loadVideoController(event),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final videoPlayerController = snapshot.data;
|
final videoPlayerController = snapshot.data;
|
||||||
if (videoPlayerController == null) {
|
if (videoPlayerController == null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user