chore: Follow up videoplayer
Signed-off-by: Christian Kußowski <c.kussowski@famedly.com>
This commit is contained in:
parent
55705d761d
commit
f3c36e0b09
2 changed files with 78 additions and 60 deletions
|
|
@ -68,49 +68,52 @@ class EventVideoPlayer extends StatelessWidget {
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
child: Stack(
|
child: Hero(
|
||||||
children: [
|
tag: event.eventId,
|
||||||
if (event.hasThumbnail)
|
child: Stack(
|
||||||
MxcImage(
|
children: [
|
||||||
event: event,
|
if (event.hasThumbnail)
|
||||||
isThumbnail: true,
|
MxcImage(
|
||||||
width: width,
|
event: event,
|
||||||
height: height,
|
isThumbnail: true,
|
||||||
fit: BoxFit.cover,
|
width: width,
|
||||||
placeholder: (context) => BlurHash(
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context) => BlurHash(
|
||||||
|
blurhash: blurHash,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
BlurHash(
|
||||||
blurhash: blurHash,
|
blurhash: blurHash,
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
)
|
Center(
|
||||||
else
|
child: CircleAvatar(
|
||||||
BlurHash(
|
child: supportsVideoPlayer
|
||||||
blurhash: blurHash,
|
? const Icon(Icons.play_arrow_outlined)
|
||||||
width: width,
|
: const Icon(Icons.file_download_outlined),
|
||||||
height: height,
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
|
||||||
Center(
|
|
||||||
child: CircleAvatar(
|
|
||||||
child: supportsVideoPlayer
|
|
||||||
? const Icon(Icons.play_arrow_outlined)
|
|
||||||
: const Icon(Icons.file_download_outlined),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
if (duration != null)
|
|
||||||
Positioned(
|
|
||||||
bottom: 8,
|
|
||||||
left: 16,
|
|
||||||
child: Text(
|
|
||||||
'${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}',
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
backgroundColor: Colors.black.withAlpha(32),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
if (duration != null)
|
||||||
|
Positioned(
|
||||||
|
bottom: 8,
|
||||||
|
left: 16,
|
||||||
|
child: Text(
|
||||||
|
'${duration.inMinutes.toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
backgroundColor: Colors.black.withAlpha(32),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -70,13 +70,15 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
await videoPlayerController.initialize();
|
await videoPlayerController.initialize();
|
||||||
|
|
||||||
// Create a ChewieController on top.
|
// Create a ChewieController on top.
|
||||||
_chewieController = ChewieController(
|
setState(() {
|
||||||
videoPlayerController: videoPlayerController,
|
_chewieController = ChewieController(
|
||||||
useRootNavigator: !kIsWeb,
|
videoPlayerController: videoPlayerController,
|
||||||
autoPlay: true,
|
useRootNavigator: !kIsWeb,
|
||||||
autoInitialize: true,
|
autoPlay: true,
|
||||||
looping: true,
|
autoInitialize: true,
|
||||||
);
|
looping: true,
|
||||||
|
);
|
||||||
|
});
|
||||||
} on IOException catch (e) {
|
} on IOException catch (e) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
|
@ -117,33 +119,46 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
||||||
final blurHash = (widget.event.infoMap as Map<String, dynamic>)
|
final blurHash = (widget.event.infoMap as Map<String, dynamic>)
|
||||||
.tryGet<String>('xyz.amorgan.blurhash') ??
|
.tryGet<String>('xyz.amorgan.blurhash') ??
|
||||||
fallbackBlurHash;
|
fallbackBlurHash;
|
||||||
|
final infoMap = widget.event.content.tryGetMap<String, Object?>('info');
|
||||||
const width = 300.0;
|
final videoWidth = infoMap?.tryGet<int>('w') ?? 400;
|
||||||
|
final videoHeight = infoMap?.tryGet<int>('h') ?? 300;
|
||||||
|
final height = MediaQuery.of(context).size.height - 52;
|
||||||
|
final width = videoWidth * (height / videoHeight);
|
||||||
|
|
||||||
final chewieController = _chewieController;
|
final chewieController = _chewieController;
|
||||||
return chewieController != null
|
return chewieController != null
|
||||||
? Center(child: Chewie(controller: chewieController))
|
? Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
child: Chewie(controller: chewieController),
|
||||||
|
),
|
||||||
|
)
|
||||||
: Stack(
|
: Stack(
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: hasThumbnail
|
child: Hero(
|
||||||
? MxcImage(
|
tag: widget.event.eventId,
|
||||||
event: widget.event,
|
child: hasThumbnail
|
||||||
isThumbnail: true,
|
? MxcImage(
|
||||||
width: width,
|
event: widget.event,
|
||||||
fit: BoxFit.cover,
|
isThumbnail: true,
|
||||||
placeholder: (context) => BlurHash(
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (context) => BlurHash(
|
||||||
|
blurhash: blurHash,
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: BlurHash(
|
||||||
blurhash: blurHash,
|
blurhash: blurHash,
|
||||||
width: width,
|
width: width,
|
||||||
height: width,
|
height: height,
|
||||||
fit: BoxFit.cover,
|
|
||||||
),
|
),
|
||||||
)
|
),
|
||||||
: BlurHash(
|
|
||||||
blurhash: blurHash,
|
|
||||||
width: width,
|
|
||||||
height: width,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const Center(child: CircularProgressIndicator.adaptive()),
|
const Center(child: CircularProgressIndicator.adaptive()),
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue