mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-29 06:19:31 +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
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
|
||||
import 'package:flutter/material.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_minimized.dart';
|
||||
|
||||
const playerMaxHeightPercentOfScreen = 0.8;
|
||||
|
||||
class AudiobookPlayer extends HookConsumerWidget {
|
||||
const AudiobookPlayer({super.key});
|
||||
|
||||
|
|
@ -65,12 +69,13 @@ class AudiobookPlayer extends HookConsumerWidget {
|
|||
);
|
||||
|
||||
// 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;
|
||||
|
||||
// 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;
|
||||
return Theme(
|
||||
|
|
@ -82,7 +87,8 @@ class AudiobookPlayer extends HookConsumerWidget {
|
|||
onDragDown: (percentage) async {
|
||||
// preferred volume
|
||||
// set volume to 0 when dragging down
|
||||
await player.setVolume(preferredVolume * (1 - percentage));
|
||||
await player
|
||||
.setVolume(preferredVolume * (1 - percentage.clamp(0, .75)));
|
||||
},
|
||||
minHeight: playerMinHeight,
|
||||
// subtract the height of notches and other system UI
|
||||
|
|
@ -94,20 +100,14 @@ class AudiobookPlayer extends HookConsumerWidget {
|
|||
},
|
||||
curve: Curves.easeOut,
|
||||
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 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 =
|
||||
(maxImgSize - playerMinHeight) /
|
||||
(playerMaxHeight - playerMinHeight);
|
||||
final bool isFormMiniplayer =
|
||||
percentage < miniplayerPercentageDeclaration;
|
||||
|
||||
|
||||
if (!isFormMiniplayer) {
|
||||
// this calculation needs a refactor
|
||||
var percentageExpandedPlayer = percentage
|
||||
|
|
@ -116,7 +116,7 @@ class AudiobookPlayer extends HookConsumerWidget {
|
|||
1,
|
||||
)
|
||||
.clamp(0.0, 1.0);
|
||||
|
||||
|
||||
return PlayerWhenExpanded(
|
||||
imageSize: maxImgSize,
|
||||
img: imgWidget,
|
||||
|
|
@ -124,13 +124,13 @@ class AudiobookPlayer extends HookConsumerWidget {
|
|||
playPauseController: playPauseController,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
//Miniplayer
|
||||
final percentageMiniplayer = percentage.inverseLerp(
|
||||
0,
|
||||
miniplayerPercentageDeclaration,
|
||||
);
|
||||
|
||||
|
||||
return PlayerWhenMinimized(
|
||||
maxImgSize: maxImgSize,
|
||||
availWidth: availWidth,
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.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:whispering_pages/constants/sizes.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/player_form.dart';
|
||||
import 'package:whispering_pages/features/player/view/audiobook_player.dart';
|
||||
import 'package:whispering_pages/settings/app_settings_provider.dart';
|
||||
import 'package:whispering_pages/shared/extensions/inverse_lerp.dart';
|
||||
|
|
@ -45,60 +43,17 @@ class PlayerWhenExpanded extends HookConsumerWidget {
|
|||
|
||||
return Column(
|
||||
children: [
|
||||
// sized box for system status bar
|
||||
SizedBox(
|
||||
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,
|
||||
);
|
||||
},
|
||||
),
|
||||
// sized box for system status bar; not needed as not full screen
|
||||
// SizedBox(
|
||||
// height: MediaQuery.of(context).padding.top * earlyPercentage,
|
||||
// ),
|
||||
|
||||
// the pill shaped container
|
||||
// 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: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// a row with a down arrow to minimize the player, a pill shaped container to drag the player, and a cast button
|
||||
// the image
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: 8.0 * earlyPercentage),
|
||||
padding: EdgeInsets.only(
|
||||
top: AppElementSizes.paddingLarge * earlyPercentage,
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
// add a shadow to the image elevation hovering effect
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue