mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-08 20:19:29 +00:00
player made shorter since can not intercept back gestures
This commit is contained in:
parent
4a430209af
commit
a1e238fc25
5 changed files with 29 additions and 72 deletions
|
|
@ -60,7 +60,7 @@ double playerHeight(
|
||||||
|
|
||||||
// a final MiniplayerController controller = MiniplayerController();
|
// a final MiniplayerController controller = MiniplayerController();
|
||||||
@Riverpod(keepAlive: true)
|
@Riverpod(keepAlive: true)
|
||||||
MiniplayerController miniplayerController(
|
Raw<MiniplayerController> miniplayerController(
|
||||||
MiniplayerControllerRef ref,
|
MiniplayerControllerRef ref,
|
||||||
) {
|
) {
|
||||||
return MiniplayerController();
|
return MiniplayerController();
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,12 @@ final playerHeightProvider = Provider<double>.internal(
|
||||||
|
|
||||||
typedef PlayerHeightRef = ProviderRef<double>;
|
typedef PlayerHeightRef = ProviderRef<double>;
|
||||||
String _$miniplayerControllerHash() =>
|
String _$miniplayerControllerHash() =>
|
||||||
r'489579a18f4e08793de08a4828172bd924768301';
|
r'a3677e63a9823881f45a12855e74bf558322e0ec';
|
||||||
|
|
||||||
/// See also [miniplayerController].
|
/// See also [miniplayerController].
|
||||||
@ProviderFor(miniplayerController)
|
@ProviderFor(miniplayerController)
|
||||||
final miniplayerControllerProvider = Provider<MiniplayerController>.internal(
|
final miniplayerControllerProvider =
|
||||||
|
Provider<Raw<MiniplayerController>>.internal(
|
||||||
miniplayerController,
|
miniplayerController,
|
||||||
name: r'miniplayerControllerProvider',
|
name: r'miniplayerControllerProvider',
|
||||||
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
|
||||||
|
|
@ -53,6 +54,6 @@ final miniplayerControllerProvider = Provider<MiniplayerController>.internal(
|
||||||
allTransitiveDependencies: null,
|
allTransitiveDependencies: null,
|
||||||
);
|
);
|
||||||
|
|
||||||
typedef MiniplayerControllerRef = ProviderRef<MiniplayerController>;
|
typedef MiniplayerControllerRef = ProviderRef<Raw<MiniplayerController>>;
|
||||||
// ignore_for_file: type=lint
|
// ignore_for_file: type=lint
|
||||||
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
// ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
|
@ -17,6 +19,8 @@ import 'package:whispering_pages/theme/theme_from_cover_provider.dart';
|
||||||
import 'player_when_expanded.dart';
|
import 'player_when_expanded.dart';
|
||||||
import 'player_when_minimized.dart';
|
import 'player_when_minimized.dart';
|
||||||
|
|
||||||
|
const playerMaxHeightPercentOfScreen = 0.8;
|
||||||
|
|
||||||
class AudiobookPlayer extends HookConsumerWidget {
|
class AudiobookPlayer extends HookConsumerWidget {
|
||||||
const AudiobookPlayer({super.key});
|
const AudiobookPlayer({super.key});
|
||||||
|
|
||||||
|
|
@ -65,12 +69,13 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
);
|
);
|
||||||
|
|
||||||
// max height of the player is the height of the screen
|
// max height of the player is the height of the screen
|
||||||
final playerMaxHeight = MediaQuery.of(context).size.height;
|
final playerMaxHeight =
|
||||||
|
MediaQuery.of(context).size.height * playerMaxHeightPercentOfScreen;
|
||||||
|
|
||||||
final availWidth = MediaQuery.of(context).size.width;
|
final availWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
// the image width when the player is expanded
|
// the image width when the player is expanded
|
||||||
final maxImgSize = availWidth * 0.9;
|
final maxImgSize = min(playerMaxHeight * 0.5, availWidth * 0.9);
|
||||||
|
|
||||||
final preferredVolume = appSettings.playerSettings.preferredDefaultVolume;
|
final preferredVolume = appSettings.playerSettings.preferredDefaultVolume;
|
||||||
return Theme(
|
return Theme(
|
||||||
|
|
@ -82,7 +87,8 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
onDragDown: (percentage) async {
|
onDragDown: (percentage) async {
|
||||||
// preferred volume
|
// preferred volume
|
||||||
// set volume to 0 when dragging down
|
// set volume to 0 when dragging down
|
||||||
await player.setVolume(preferredVolume * (1 - percentage));
|
await player
|
||||||
|
.setVolume(preferredVolume * (1 - percentage.clamp(0, .75)));
|
||||||
},
|
},
|
||||||
minHeight: playerMinHeight,
|
minHeight: playerMinHeight,
|
||||||
// subtract the height of notches and other system UI
|
// subtract the height of notches and other system UI
|
||||||
|
|
@ -94,20 +100,14 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
},
|
},
|
||||||
curve: Curves.easeOut,
|
curve: Curves.easeOut,
|
||||||
builder: (height, percentage) {
|
builder: (height, percentage) {
|
||||||
// return SafeArea(
|
|
||||||
// child: Text(
|
|
||||||
// 'percentage: ${percentage.toStringAsFixed(2)}, height: ${height.toStringAsFixed(2)} volume: ${player.volume.toStringAsFixed(2)}',
|
|
||||||
// ),
|
|
||||||
// );
|
|
||||||
|
|
||||||
// at what point should the player switch from miniplayer to expanded player
|
// at what point should the player switch from miniplayer to expanded player
|
||||||
// at this point the image should be at its max size and in the center of the player
|
// also at this point the image should be at its max size and in the center of the player
|
||||||
final miniplayerPercentageDeclaration =
|
final miniplayerPercentageDeclaration =
|
||||||
(maxImgSize - playerMinHeight) /
|
(maxImgSize - playerMinHeight) /
|
||||||
(playerMaxHeight - playerMinHeight);
|
(playerMaxHeight - playerMinHeight);
|
||||||
final bool isFormMiniplayer =
|
final bool isFormMiniplayer =
|
||||||
percentage < miniplayerPercentageDeclaration;
|
percentage < miniplayerPercentageDeclaration;
|
||||||
|
|
||||||
if (!isFormMiniplayer) {
|
if (!isFormMiniplayer) {
|
||||||
// this calculation needs a refactor
|
// this calculation needs a refactor
|
||||||
var percentageExpandedPlayer = percentage
|
var percentageExpandedPlayer = percentage
|
||||||
|
|
@ -116,7 +116,7 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
.clamp(0.0, 1.0);
|
.clamp(0.0, 1.0);
|
||||||
|
|
||||||
return PlayerWhenExpanded(
|
return PlayerWhenExpanded(
|
||||||
imageSize: maxImgSize,
|
imageSize: maxImgSize,
|
||||||
img: imgWidget,
|
img: imgWidget,
|
||||||
|
|
@ -124,13 +124,13 @@ class AudiobookPlayer extends HookConsumerWidget {
|
||||||
playPauseController: playPauseController,
|
playPauseController: playPauseController,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Miniplayer
|
//Miniplayer
|
||||||
final percentageMiniplayer = percentage.inverseLerp(
|
final percentageMiniplayer = percentage.inverseLerp(
|
||||||
0,
|
0,
|
||||||
miniplayerPercentageDeclaration,
|
miniplayerPercentageDeclaration,
|
||||||
);
|
);
|
||||||
|
|
||||||
return PlayerWhenMinimized(
|
return PlayerWhenMinimized(
|
||||||
maxImgSize: maxImgSize,
|
maxImgSize: maxImgSize,
|
||||||
availWidth: availWidth,
|
availWidth: availWidth,
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:list_wheel_scroll_view_nls/list_wheel_scroll_view_nls.dart';
|
import 'package:list_wheel_scroll_view_nls/list_wheel_scroll_view_nls.dart';
|
||||||
import 'package:miniplayer/miniplayer.dart';
|
|
||||||
import 'package:shelfsdk/audiobookshelf_api.dart';
|
import 'package:shelfsdk/audiobookshelf_api.dart';
|
||||||
import 'package:whispering_pages/constants/sizes.dart';
|
import 'package:whispering_pages/constants/sizes.dart';
|
||||||
import 'package:whispering_pages/features/player/providers/audiobook_player.dart';
|
import 'package:whispering_pages/features/player/providers/audiobook_player.dart';
|
||||||
import 'package:whispering_pages/features/player/providers/currently_playing_provider.dart';
|
import 'package:whispering_pages/features/player/providers/currently_playing_provider.dart';
|
||||||
import 'package:whispering_pages/features/player/providers/player_form.dart';
|
|
||||||
import 'package:whispering_pages/features/player/view/audiobook_player.dart';
|
import 'package:whispering_pages/features/player/view/audiobook_player.dart';
|
||||||
import 'package:whispering_pages/settings/app_settings_provider.dart';
|
import 'package:whispering_pages/settings/app_settings_provider.dart';
|
||||||
import 'package:whispering_pages/shared/extensions/inverse_lerp.dart';
|
import 'package:whispering_pages/shared/extensions/inverse_lerp.dart';
|
||||||
|
|
@ -45,60 +43,17 @@ class PlayerWhenExpanded extends HookConsumerWidget {
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
// sized box for system status bar
|
// sized box for system status bar; not needed as not full screen
|
||||||
SizedBox(
|
// SizedBox(
|
||||||
height: MediaQuery.of(context).padding.top * earlyPercentage,
|
// height: MediaQuery.of(context).padding.top * earlyPercentage,
|
||||||
),
|
// ),
|
||||||
// a row with a down arrow to minimize the player, a pill shaped container to drag the player, and a cast button
|
|
||||||
ConstrainedBox(
|
|
||||||
constraints: BoxConstraints(
|
|
||||||
maxHeight: 100 * earlyPercentage,
|
|
||||||
),
|
|
||||||
child: Opacity(
|
|
||||||
opacity: earlyPercentage,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.only(top: 8.0 * earlyPercentage),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
// the down arrow
|
|
||||||
IconButton(
|
|
||||||
iconSize: 30,
|
|
||||||
icon: const Icon(Icons.keyboard_arrow_down),
|
|
||||||
onPressed: () {
|
|
||||||
// minimize the player
|
|
||||||
ref.read(miniplayerControllerProvider).animateToHeight(
|
|
||||||
state: PanelState.MIN,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
// the pill shaped container
|
// a row with a down arrow to minimize the player, a pill shaped container to drag the player, and a cast button
|
||||||
// SizedBox(
|
|
||||||
// height: 6,
|
|
||||||
// width: 32,
|
|
||||||
// child: Container(
|
|
||||||
// decoration: BoxDecoration(
|
|
||||||
// color: Theme.of(context).colorScheme.secondary,
|
|
||||||
// borderRadius: BorderRadius.circular(32),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// the cast button
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.cast),
|
|
||||||
onPressed: () {},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// the image
|
// the image
|
||||||
Padding(
|
Padding(
|
||||||
padding: EdgeInsets.only(top: 8.0 * earlyPercentage),
|
padding: EdgeInsets.only(
|
||||||
|
top: AppElementSizes.paddingLarge * earlyPercentage,
|
||||||
|
),
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
// add a shadow to the image elevation hovering effect
|
// add a shadow to the image elevation hovering effect
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ class ScaffoldWithNavBar extends HookConsumerWidget {
|
||||||
// final playerProgress =
|
// final playerProgress =
|
||||||
// useValueListenable(ref.watch(playerExpandProgressNotifierProvider));
|
// useValueListenable(ref.watch(playerExpandProgressNotifierProvider));
|
||||||
final playerProgress = ref.watch(playerHeightProvider);
|
final playerProgress = ref.watch(playerHeightProvider);
|
||||||
final playerMaxHeight = MediaQuery.of(context).size.height;
|
final playerMaxHeight =
|
||||||
|
MediaQuery.of(context).size.height * playerMaxHeightPercentOfScreen;
|
||||||
var percentExpanded = (playerProgress - playerMinHeight) /
|
var percentExpanded = (playerProgress - playerMinHeight) /
|
||||||
(playerMaxHeight - playerMinHeight);
|
(playerMaxHeight - playerMinHeight);
|
||||||
// Clamp the value between 0 and 1
|
// Clamp the value between 0 and 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue