-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0b63d4
commit 011d169
Showing
9 changed files
with
506 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}, | ||
), | ||
), | ||
], | ||
)), | ||
); | ||
} | ||
} |
Oops, something went wrong.