Skip to content

Commit

Permalink
new miniplayer implts(beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
HemantKArya committed Apr 12, 2024
1 parent a0b63d4 commit 011d169
Show file tree
Hide file tree
Showing 9 changed files with 506 additions and 198 deletions.
113 changes: 113 additions & 0 deletions lib/blocs/mini_player/mini_player_cubit.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'dart:async';
import 'dart:developer';
import 'package:Bloomee/blocs/mediaPlayer/bloomee_player_cubit.dart';
import 'package:Bloomee/model/songModel.dart';
import 'package:Bloomee/routes_and_consts/global_conts.dart';
import 'package:audio_service/audio_service.dart';
import 'package:bloc/bloc.dart';
part 'mini_player_state.dart';

class MiniPlayerCubit extends Cubit<MiniPlayerState> {
BloomeePlayerCubit bloomeePlayerCubit;
StreamSubscription? _linkSub;
StreamSubscription? _playerSub;
MiniPlayerCubit({required this.bloomeePlayerCubit})
: super(MiniPlayerInitial()) {
subscribeToPlayer();
subscribeLinkProc();
}

void subscribeLinkProc() async {
_linkSub =
bloomeePlayerCubit.bloomeePlayer.isLinkProcessing.listen((event) {
if (event) {
log("MiniPlayerCubit: isLinkProcessing");
emit(state.copyWith(
isProcessing: true,
));
}
});
}

void subscribeToPlayer() async {
_playerSub = bloomeePlayerCubit.bloomeePlayer.playbackState.listen((value) {
switch (value.processingState) {
case AudioProcessingState.idle:
emit(MiniPlayerInitial());
break;
case AudioProcessingState.loading:
if (bloomeePlayerCubit.bloomeePlayer.mediaItem.value != null) {
emit(state.copyWith(
mediaItem: mediaItem2MediaItemModel(
bloomeePlayerCubit.bloomeePlayer.mediaItem.value!),
isPlaying: false,
isBuffering: true,
isProcessing: true,
isCompleted: false,
));
}
break;
case AudioProcessingState.buffering:
if (bloomeePlayerCubit.bloomeePlayer.mediaItem.value != null) {
emit(state.copyWith(
mediaItem: mediaItem2MediaItemModel(
bloomeePlayerCubit.bloomeePlayer.mediaItem.value!),
isPlaying: false,
isBuffering: true,
isProcessing: false,
isCompleted: false,
));
}
break;
case AudioProcessingState.ready:
if (bloomeePlayerCubit.bloomeePlayer.mediaItem.value != null) {
emit(state.copyWith(
mediaItem: mediaItem2MediaItemModel(
bloomeePlayerCubit.bloomeePlayer.mediaItem.value!),
isPlaying: value.playing,
isBuffering: false,
isProcessing: false,
isCompleted: false,
));
}
break;

case AudioProcessingState.completed:
log("MiniPlayerCubit: completed");
emit(state.copyWith(isCompleted: true));

break;
case AudioProcessingState.error:
emit(MiniPlayerError());
break;
}

if (value.playing) {
emit(state.copyWith(
mediaItem: mediaItem2MediaItemModel(
bloomeePlayerCubit.bloomeePlayer.mediaItem.value!),
isPlaying: true,
isBuffering: false,
isProcessing: false,
isCompleted: false,
));
} else {
emit(state.copyWith(
mediaItem: mediaItem2MediaItemModel(
bloomeePlayerCubit.bloomeePlayer.mediaItem.value!),
isPlaying: false,
isBuffering: false,
isProcessing: false,
isCompleted: false,
));
}
});
}

@override
Future<void> close() {
_playerSub?.cancel();
_linkSub?.cancel();
return super.close();
}
}
97 changes: 97 additions & 0 deletions lib/blocs/mini_player/mini_player_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
part of 'mini_player_cubit.dart';

class MiniPlayerState {
final MediaItemModel mediaItem;
final bool isPlaying;
final bool isBuffering;
final bool isProcessing;
final bool isCompleted;
const MiniPlayerState({
required this.mediaItem,
required this.isPlaying,
required this.isBuffering,
required this.isProcessing,
this.isCompleted = false,
});

MiniPlayerState copyWith({
MediaItemModel? mediaItem,
bool? isPlaying,
bool? isBuffering,
bool? isProcessing,
bool? isCompleted,
}) {
return MiniPlayerState(
mediaItem: mediaItem ?? this.mediaItem,
isPlaying: isPlaying ?? this.isPlaying,
isBuffering: isBuffering ?? this.isBuffering,
isProcessing: isProcessing ?? this.isProcessing,
isCompleted: isCompleted ?? this.isCompleted,
);
}

@override
bool operator ==(covariant MiniPlayerState other) {
if (identical(this, other)) return true;

return other.mediaItem == mediaItem &&
other.isPlaying == isPlaying &&
other.isBuffering == isBuffering &&
other.isProcessing == isProcessing &&
other.isCompleted == isCompleted;
}

@override
int get hashCode {
return mediaItem.hashCode ^
isPlaying.hashCode ^
isBuffering.hashCode ^
isProcessing.hashCode ^
isCompleted.hashCode;
}
}

class MiniPlayerInitial extends MiniPlayerState {
MiniPlayerInitial()
: super(
mediaItem: mediaItemModelNull,
isPlaying: false,
isBuffering: false,
isProcessing: false,
);
}

class MiniPlayerWorking extends MiniPlayerState {
const MiniPlayerWorking({
required MediaItemModel mediaItem,
required bool isPlaying,
required bool isBuffering,
required bool isProcessing,
}) : super(
mediaItem: mediaItem,
isPlaying: isPlaying,
isBuffering: isBuffering,
isProcessing: isProcessing,
);
}

class MiniPlayerError extends MiniPlayerState {
MiniPlayerError()
: super(
mediaItem: mediaItemModelNull,
isPlaying: false,
isBuffering: false,
isProcessing: false,
);
}

class MiniPlayerCompleted extends MiniPlayerState {
const MiniPlayerCompleted({required MediaItemModel mediaItemModel})
: super(
mediaItem: mediaItemModel,
isPlaying: false,
isBuffering: false,
isProcessing: false,
);
}
5 changes: 5 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:developer';
import 'dart:io' as io;
import 'package:Bloomee/blocs/downloader/cubit/downloader_cubit.dart';
import 'package:Bloomee/blocs/internet_connectivity/cubit/connectivity_cubit.dart';
import 'package:Bloomee/blocs/mini_player/mini_player_cubit.dart';
import 'package:Bloomee/blocs/settings_cubit/cubit/settings_cubit.dart';
import 'package:Bloomee/blocs/timer/timer_bloc.dart';
import 'package:Bloomee/screens/widgets/snackbar.dart';
Expand Down Expand Up @@ -164,6 +165,10 @@ class _MyAppState extends State<MyApp> {
create: (context) => bloomeePlayerCubit,
lazy: false,
),
BlocProvider(
create: (context) =>
MiniPlayerCubit(bloomeePlayerCubit: bloomeePlayerCubit),
lazy: true),
BlocProvider(
create: (context) => BloomeeDBCubit(),
lazy: false,
Expand Down
4 changes: 2 additions & 2 deletions lib/routes_and_consts/routes.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:Bloomee/screens/widgets/global_footer.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:Bloomee/routes_and_consts/global_str_consts.dart';
Expand All @@ -9,7 +10,6 @@ import 'package:Bloomee/screens/screen/library_views/import_media_view.dart';
import 'package:Bloomee/screens/screen/library_views/playlist_screen.dart';
import 'package:Bloomee/screens/screen/offline_screen.dart';
import 'package:Bloomee/screens/screen/search_screen.dart';
import 'package:Bloomee/screens/widgets/global_navbar.dart';
import 'package:Bloomee/screens/screen/chart/chart_view.dart';

class GlobalRoutes {
Expand Down Expand Up @@ -63,7 +63,7 @@ class GlobalRoutes {
),
StatefulShellRoute.indexedStack(
builder: (context, state, navigationShell) =>
ScaffholdWithNavbar(navigationShell: navigationShell),
GlobalFooter(navigationShell: navigationShell),
branches: [
// StatefulShellBranch(routes: [
// GoRoute(
Expand Down
15 changes: 12 additions & 3 deletions lib/screens/screen/add_to_playlist_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _AddToPlaylistScreenState extends State<AddToPlaylistScreen> {
color:
Default_Theme.primaryColor2,
fontWeight: FontWeight.bold,
fontSize: 20)),
fontSize: 17)),
),
),
Text(
Expand All @@ -121,7 +121,7 @@ class _AddToPlaylistScreenState extends State<AddToPlaylistScreen> {
color: Default_Theme.primaryColor2
.withOpacity(0.5),
fontWeight: FontWeight.bold,
fontSize: 18)),
fontSize: 15)),
),
],
),
Expand Down Expand Up @@ -222,6 +222,9 @@ class _AddToPlaylistScreenState extends State<AddToPlaylistScreen> {
],
),
floatingActionButton: FloatingActionButton.extended(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50),
),
icon: const Icon(
MingCute.add_fill,
size: 25,
Expand All @@ -230,7 +233,13 @@ class _AddToPlaylistScreenState extends State<AddToPlaylistScreen> {
onPressed: () {
createPlaylistBottomSheet(context);
},
label: const Text("Create New Playlist"),
label: Text(
"Create New Playlist",
style: Default_Theme.secondoryTextStyle.merge(const TextStyle(
color: Default_Theme.primaryColor1,
fontWeight: FontWeight.bold,
fontSize: 15)),
),
),
);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/screens/screen/audioPlayer_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ class _AudioPlayerViewState extends State<AudioPlayerView> {
false
? Default_Theme.accentColor1
: Default_Theme.accentColor2,
thumbRadius: 0,
thumbRadius: 5,
thumbColor:
snapshot.data?.currentPlayerState.playing ??
false
? Default_Theme.accentColor1
: Default_Theme.accentColor2,
bufferedBarColor: snapshot
.data?.currentPlayerState.playing ??
false
Expand Down
1 change: 0 additions & 1 deletion lib/screens/screen/explore_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import 'package:Bloomee/screens/widgets/sign_board_widget.dart';
import 'package:Bloomee/screens/widgets/song_tile.dart';
import 'package:Bloomee/services/db/cubit/bloomee_db_cubit.dart';
import 'package:Bloomee/utils/app_updater.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:Bloomee/screens/screen/home_views/notification_view.dart';
import 'package:Bloomee/screens/screen/home_views/setting_view.dart';
Expand Down
69 changes: 69 additions & 0 deletions lib/screens/widgets/global_footer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:google_nav_bar/google_nav_bar.dart';
import 'package:icons_plus/icons_plus.dart';
import 'package:Bloomee/screens/widgets/mini_player_widget.dart';
import '../../theme_data/default.dart';

class GlobalFooter extends StatelessWidget {
const GlobalFooter({super.key, required this.navigationShell});
final StatefulNavigationShell navigationShell;
@override
Widget build(BuildContext context) {
return Scaffold(
body: navigationShell,
backgroundColor: Default_Theme.themeColor,
drawerScrimColor: Default_Theme.themeColor,
bottomNavigationBar: SafeArea(
child: Wrap(
children: [
const MiniPlayerWidget(),
Container(
color: Colors.transparent,
margin: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
child: GNav(
gap: 7.0,
tabBackgroundColor: Default_Theme.accentColor2.withOpacity(0.22),
color: Default_Theme.primaryColor2,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
activeColor: Default_Theme.accentColor2,
textStyle: Default_Theme.secondoryTextStyleMedium.merge(
const TextStyle(
color: Default_Theme.accentColor2, fontSize: 18)),
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
backgroundColor: Default_Theme.themeColor.withOpacity(0.3),
tabs: const [
// GButton(
// icon: MingCute.home_4_fill,
// iconSize: 27,
// text: "Test",
// ),
GButton(
icon: MingCute.home_4_fill,
iconSize: 27,
text: "Home",
),
GButton(
icon: MingCute.book_5_fill,
text: "Library",
),
GButton(
icon: MingCute.search_2_fill,
text: "Search",
),
GButton(
icon: MingCute.folder_download_fill,
text: "Offline",
),
],
selectedIndex: navigationShell.currentIndex,
onTabChange: (value) {
navigationShell.goBranch(value);
},
),
),
],
)),
);
}
}
Loading

0 comments on commit 011d169

Please sign in to comment.