This commit is contained in:
@ -1,14 +1,14 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:cached_video_player_plus/cached_video_player_plus.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
|
||||
import 'package:f0ckapp/controller/media_controller.dart';
|
||||
import 'package:f0ckapp/models/media_item.dart';
|
||||
import 'package:f0ckapp/widgets/videooverlay_widget.dart';
|
||||
import 'package:f0ckapp/models/item.dart';
|
||||
import 'package:f0ckapp/widgets/video_controls_overlay.dart';
|
||||
import 'package:f0ckapp/controller/mediacontroller.dart';
|
||||
|
||||
class VideoWidget extends StatefulWidget {
|
||||
final MediaItem details;
|
||||
@ -44,15 +44,13 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||
);
|
||||
await _controller.initialize();
|
||||
setState(() {});
|
||||
|
||||
_controller.addListener(() => setState(() {}));
|
||||
_controller.setLooping(true);
|
||||
_controller.setVolume(controller.muted.value ? 0.0 : 1.0);
|
||||
|
||||
if (widget.isActive) {
|
||||
_controller.play();
|
||||
}
|
||||
_controller.setLooping(true);
|
||||
|
||||
_controller.setVolume(controller.muted.value ? 0.0 : 1.0);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -96,34 +94,31 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||
|
||||
bool isAudio = widget.details.mime.startsWith('audio');
|
||||
|
||||
if (widget.fullScreen) {
|
||||
return Stack(
|
||||
Widget mediaContent;
|
||||
if (isAudio) {
|
||||
mediaContent = CachedNetworkImage(
|
||||
imageUrl: widget.details.coverUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorWidget: (c, e, s) => Image.asset(
|
||||
'assets/images/music.webp',
|
||||
fit: BoxFit.contain,
|
||||
width: double.infinity,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
mediaContent = _controller.value.isInitialized
|
||||
? CachedVideoPlayerPlus(_controller)
|
||||
: const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return AspectRatio(
|
||||
aspectRatio: _controller.value.isInitialized
|
||||
? _controller.value.aspectRatio
|
||||
: (isAudio ? 16 / 9 : 9 / 16),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: _controller.value.isInitialized
|
||||
? _controller.value.aspectRatio
|
||||
: 9 / 16,
|
||||
child: GestureDetector(
|
||||
onTap: _onTap,
|
||||
child: isAudio
|
||||
? CachedNetworkImage(
|
||||
imageUrl: widget.details.coverUrl,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) =>
|
||||
const CircularProgressIndicator(),
|
||||
errorWidget: (context, url, error) => Image.asset(
|
||||
'assets/images/music.webp',
|
||||
fit: BoxFit.contain,
|
||||
width: double.infinity,
|
||||
),
|
||||
)
|
||||
: _controller.value.isInitialized
|
||||
? CachedVideoPlayerPlus(_controller)
|
||||
: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
),
|
||||
GestureDetector(onTap: _onTap, child: mediaContent),
|
||||
if (_controller.value.isInitialized && _showControls)
|
||||
Positioned.fill(
|
||||
child: GestureDetector(
|
||||
@ -132,61 +127,18 @@ class _VideoWidgetState extends State<VideoWidget> {
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
child: VideoControlsOverlay(
|
||||
controller: _controller,
|
||||
button: () => _onTap(ctrlButton: true),
|
||||
onOverlayTap: () => _onTap(ctrlButton: true),
|
||||
muted: muted,
|
||||
onMuteToggle: () {
|
||||
controller.toggleMuted();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: _controller.value.isInitialized
|
||||
? _controller.value.aspectRatio
|
||||
: 9 / 16,
|
||||
child: Stack(
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: _onTap,
|
||||
child: isAudio
|
||||
? CachedNetworkImage(
|
||||
imageUrl: widget.details.coverUrl,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) =>
|
||||
const CircularProgressIndicator(),
|
||||
errorWidget: (context, url, error) => Image.asset(
|
||||
'assets/images/music.webp',
|
||||
fit: BoxFit.contain,
|
||||
width: double.infinity,
|
||||
),
|
||||
)
|
||||
: _controller.value.isInitialized
|
||||
? CachedVideoPlayerPlus(_controller)
|
||||
: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
if (_controller.value.isInitialized && _showControls) ...[
|
||||
IgnorePointer(
|
||||
ignoring: true,
|
||||
child: Container(
|
||||
color: Colors.black.withValues(alpha: 0.5),
|
||||
width: double.infinity,
|
||||
height: double.infinity,
|
||||
),
|
||||
),
|
||||
VideoControlsOverlay(
|
||||
controller: _controller,
|
||||
button: () => _onTap(ctrlButton: true),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user