mirror of
https://github.com/immich-app/immich.git
synced 2024-12-27 10:58:13 +02:00
4ef4cc8016
* Fixes double video auto initialize issue and placeholder for video controller
* WIP unravel stack index
* Refactors video player controller
format
fixing video
format
Working
format
* Fixes hide on pause
* Got hiding when tapped working
* Hides controls when video starts and fixes placeholder for memory card
Remove prints
* Fixes show controls with microtask
* fix LivePhotos not playing
* removes unused function callbacks and moves wakelock
* Update motion video
* Fixing motion photo playing
* Renames to isPlayingVideo
* Fixes playing video on change
* pause on dispose
* fixing issues with sync between controls
* Adds gallery app bar
* Switches to memoized
* Fixes pause
* Revert "Switches to memoized"
This reverts commit 234e6741de
.
* uses stateful widget
* Fixes double video play by using provider and new chewie video player
wip
format
Fixes motion photos
format
---------
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
126 lines
4.1 KiB
Dart
126 lines
4.1 KiB
Dart
import 'dart:math';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/show_controls.provider.dart';
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/video_player_controls_provider.dart';
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/video_player_value_provider.dart';
|
|
|
|
/// The video controls for the [videPlayerControlsProvider]
|
|
class VideoControls extends ConsumerWidget {
|
|
const VideoControls({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final duration =
|
|
ref.watch(videoPlaybackValueProvider.select((v) => v.duration));
|
|
final position =
|
|
ref.watch(videoPlaybackValueProvider.select((v) => v.position));
|
|
|
|
return AnimatedOpacity(
|
|
opacity: ref.watch(showControlsProvider) ? 1.0 : 0.0,
|
|
duration: const Duration(milliseconds: 100),
|
|
child: OrientationBuilder(
|
|
builder: (context, orientation) => Container(
|
|
padding: EdgeInsets.symmetric(
|
|
horizontal: orientation == Orientation.portrait ? 12.0 : 64.0,
|
|
),
|
|
color: Colors.black.withOpacity(0.4),
|
|
child: Padding(
|
|
padding: MediaQuery.of(context).orientation == Orientation.portrait
|
|
? const EdgeInsets.symmetric(horizontal: 12.0)
|
|
: const EdgeInsets.symmetric(horizontal: 64.0),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
_formatDuration(position),
|
|
style: TextStyle(
|
|
fontSize: 14.0,
|
|
color: Colors.white.withOpacity(.75),
|
|
fontWeight: FontWeight.normal,
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Slider(
|
|
value: duration == Duration.zero
|
|
? 0.0
|
|
: min(
|
|
position.inMicroseconds /
|
|
duration.inMicroseconds *
|
|
100,
|
|
100,
|
|
),
|
|
min: 0,
|
|
max: 100,
|
|
thumbColor: Colors.white,
|
|
activeColor: Colors.white,
|
|
inactiveColor: Colors.white.withOpacity(0.75),
|
|
onChanged: (position) {
|
|
ref.read(videoPlayerControlsProvider.notifier).position =
|
|
position;
|
|
},
|
|
),
|
|
),
|
|
Text(
|
|
_formatDuration(duration),
|
|
style: TextStyle(
|
|
fontSize: 14.0,
|
|
color: Colors.white.withOpacity(.75),
|
|
fontWeight: FontWeight.normal,
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: Icon(
|
|
ref.watch(
|
|
videoPlayerControlsProvider.select((value) => value.mute),
|
|
)
|
|
? Icons.volume_off
|
|
: Icons.volume_up,
|
|
),
|
|
onPressed: () => ref
|
|
.read(videoPlayerControlsProvider.notifier)
|
|
.toggleMute(),
|
|
color: Colors.white,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _formatDuration(Duration position) {
|
|
final ms = position.inMilliseconds;
|
|
|
|
int seconds = ms ~/ 1000;
|
|
final int hours = seconds ~/ 3600;
|
|
seconds = seconds % 3600;
|
|
final minutes = seconds ~/ 60;
|
|
seconds = seconds % 60;
|
|
|
|
final hoursString = hours >= 10
|
|
? '$hours'
|
|
: hours == 0
|
|
? '00'
|
|
: '0$hours';
|
|
|
|
final minutesString = minutes >= 10
|
|
? '$minutes'
|
|
: minutes == 0
|
|
? '00'
|
|
: '0$minutes';
|
|
|
|
final secondsString = seconds >= 10
|
|
? '$seconds'
|
|
: seconds == 0
|
|
? '00'
|
|
: '0$seconds';
|
|
|
|
final formattedTime =
|
|
'${hoursString == '00' ? '' : '$hoursString:'}$minutesString:$secondsString';
|
|
|
|
return formattedTime;
|
|
}
|
|
}
|