From 871d694416448897c803c70730bbba9ca948f206 Mon Sep 17 00:00:00 2001 From: Angshuman Barpujari Date: Fri, 3 Jul 2020 23:21:58 +0530 Subject: [PATCH] now we contruct player logic once then pass it who needs it, it fixes the audio control problem --- .../raylex/player/PlayerController.java | 2 +- lib/logic/models/modelMiniplayer.dart | 12 ++ lib/logic/playerLogic.dart | 24 ++- lib/main.dart | 5 +- lib/ux/components/appBars/libraryAppBar.dart | 188 +++--------------- lib/ux/components/appBars/playerAppBar.dart | 4 +- lib/ux/components/cards/miniPlayer.dart | 182 +++++++++++++++++ .../components/cards/playerAlbumArtCard.dart | 20 +- .../components/groups/groupPlayerControl.dart | 43 ++-- .../groups/groupPlayerTextMeta.dart | 27 +-- .../components/lists/verticalListSimple.dart | 6 +- lib/ux/pages/libraryPages.dart | 9 +- lib/ux/pages/navPages.dart | 35 +++- lib/ux/pages/playerUIPage.dart | 89 ++++++--- 14 files changed, 373 insertions(+), 273 deletions(-) create mode 100644 lib/logic/models/modelMiniplayer.dart create mode 100644 lib/ux/components/cards/miniPlayer.dart diff --git a/android/app/src/main/java/com/raysummee/raylex/raylex/player/PlayerController.java b/android/app/src/main/java/com/raysummee/raylex/raylex/player/PlayerController.java index 6122062..e31128c 100644 --- a/android/app/src/main/java/com/raysummee/raylex/raylex/player/PlayerController.java +++ b/android/app/src/main/java/com/raysummee/raylex/raylex/player/PlayerController.java @@ -170,7 +170,7 @@ public void run(){ } long time = exoPlayer.getCurrentPosition(); channel.invokeMethod("audio.onCurrentPosition", time); - handler.postDelayed(this, 200); + handler.postDelayed(this, 20); } catch (Exception e) { Log.w("ID", "When running handler", e); diff --git a/lib/logic/models/modelMiniplayer.dart b/lib/logic/models/modelMiniplayer.dart new file mode 100644 index 0000000..05bc71b --- /dev/null +++ b/lib/logic/models/modelMiniplayer.dart @@ -0,0 +1,12 @@ +import 'package:flutter/material.dart'; + +class ModelMiniPlayer extends ChangeNotifier{ + /* bool _miniPlayerShowing=true; + + bool get miniPlayerShowing=>_miniPlayerShowing; + + set miniPlayerShowing(bool isShowing){ + _miniPlayerShowing = isShowing; + notifyListeners(); + }*/ +} \ No newline at end of file diff --git a/lib/logic/playerLogic.dart b/lib/logic/playerLogic.dart index fb64dfc..12cdef9 100644 --- a/lib/logic/playerLogic.dart +++ b/lib/logic/playerLogic.dart @@ -67,18 +67,22 @@ class PlayerLogic{ }); } - void nextSong(List songinfos) async{ - int pos = await getPlaylistPosition(); - print("current playlist $pos"); - setPlaylistPostion(pos + 1); - print("setting new playlist pos "); - playMusic(songinfos.elementAt(await getPlaylistPosition()).uri); - print("nextsong ${await getPlaylistPosition()}"); + void nextSong(List songinfos, int currentpos) async{ + if(currentpos songinfos) async{ - setPlaylistPostion((await getPlaylistPosition()) - 1); - playMusic(songinfos.elementAt(await getPlaylistPosition()).uri); + void prevSong(List songinfos, int currentpos) async{ + if(currentpos>0){ + playMusic(songinfos.elementAt(--currentpos).uri); + print("nextsong ${--currentpos}"); + }else{ + print("no more songs"); + } } Stream get onPlayerStateChanged => _playerStateController.stream; diff --git a/lib/main.dart b/lib/main.dart index 7f6c9d1..5d25be3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,4 @@ +import 'package:Raylex/logic/models/modelMiniplayer.dart'; import 'package:Raylex/logic/models/playerStateNotify.dart'; import 'package:Raylex/logic/models/playlistPosition.dart'; import 'package:Raylex/ux/pages/navPages.dart'; @@ -8,8 +9,7 @@ import 'package:provider/provider.dart'; void main(){ WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith( - systemNavigationBarColor: Colors.lightBlue, - statusBarColor: Colors.blue + systemNavigationBarColor: Colors.lightBlue.shade600.withAlpha(210), )); runApp(Launch()); } @@ -21,6 +21,7 @@ class Launch extends StatelessWidget { providers: [ ChangeNotifierProvider(create: (_)=>PlayerStateNotify()), ChangeNotifierProvider(create: (_)=>PlaylistPosition()), + ChangeNotifierProvider(create: (_)=>ModelMiniPlayer()), ], child: MaterialApp( routes: { diff --git a/lib/ux/components/appBars/libraryAppBar.dart b/lib/ux/components/appBars/libraryAppBar.dart index 6383b38..b6bfcdd 100644 --- a/lib/ux/components/appBars/libraryAppBar.dart +++ b/lib/ux/components/appBars/libraryAppBar.dart @@ -1,176 +1,42 @@ -import 'dart:async'; -import 'package:Raylex/logic/models/playerStateNotify.dart'; -import 'package:Raylex/logic/models/playlistPosition.dart'; -import 'package:Raylex/logic/models/songInfo.dart'; -import 'package:Raylex/logic/playerLogic.dart'; +import 'dart:ui'; + import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -class LibraryAppBar extends StatefulWidget { - @override - _LibraryAppBarState createState() => _LibraryAppBarState(); -} -class _LibraryAppBarState extends State with TickerProviderStateMixin { - AnimationController __animationController; - StreamSubscription __subscriptionPlayerStateChanged; - PlayerLogic _playerLogic; - bool isPlaying=false; - bool isActive=true; - PlayerStateNotify appstate; - //PlaylistPosition appstatepos; - - @override - void didChangeDependencies(){ - super.didChangeDependencies(); - if(appstate==null) - appstate=Provider.of(context); - //if(appstatepos==null) - //appstatepos = Provider.of(context); - //_playerLogic.getPlaylistPosition().then((value) => appstatepos.index = value); - print("didchangeddependencies library"); - if(__subscriptionPlayerStateChanged!=null){ - print("canceled onstatechangedSecondary"); - __subscriptionPlayerStateChanged.cancel(); - __subscriptionPlayerStateChanged = null; - }else{ - isActive = true; - _playerLogic.setMethodCallHandler(); - print("creating onstateSecondary"); - __subscriptionPlayerStateChanged = _playerLogic.onPlayerSecondaryStateChanged.handleError((e)=>print("streamerror $e")).listen((state) { - print("onStateChangedSecondary"); - - if(state == true){ - setState(() { - isPlaying = true; - }); - __animationController.forward(); - } - if(state == false){ - setState(() { - isPlaying = false; - }); - __animationController.reverse(); - } - - }); - } - _playerLogic.onInstanceIsPlaying().then((isP) { - setState(() { - isPlaying = isP; - }); - if(isP){ - __animationController.forward(from: __animationController.upperBound); - }else{ - __animationController.reverse(from: __animationController.lowerBound); - } - }); - } +class LibraryAppBar extends StatelessWidget{ - @override - void initState(){ - super.initState(); - print("library init"); - _playerLogic = PlayerLogic(); - __animationController = AnimationController( - vsync: this, - duration: Duration(milliseconds: 300), - ); - } - - - @override - void dispose(){ - super.dispose(); - print("library dispose"); - __animationController.dispose(); - __subscriptionPlayerStateChanged.cancel(); - //appstate.dispose(); - } @override Widget build(BuildContext context) { - return AppBar( - backgroundColor: Colors.lightBlue, - flexibleSpace: SafeArea( + return SafeArea( bottom: false, - child: Container( - margin: EdgeInsets.fromLTRB(20, 20, 20, 20), - alignment: Alignment.bottomLeft, - height: 200, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Container( - margin: EdgeInsets.only(bottom: 2), - child: Text( - "Library", - style: TextStyle( - color: Colors.white, - fontSize: 27, - fontWeight: FontWeight.bold - ) - ), - ), - Row( + top: false, + child: ClipRRect( + child: BackdropFilter( + filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), + child: Container( + color: Colors.lightBlue.withAlpha(200), + alignment: Alignment.bottomLeft, + height: 100, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - IconButton( - icon: Icon( - Icons.fast_rewind, - color: Colors.white, - ), - onPressed: (){ - if(appstate.songinfos!=null && appstate.songinfos.isNotEmpty){ - _playerLogic.prevSong(appstate.songinfos); - //appstatepos.index=appstatepos.index-1; - } - else - print("error prev"); - } - ), - IconButton( - iconSize: 35, - icon: AnimatedIcon( - icon: AnimatedIcons.play_pause, - progress: __animationController, - color: Colors.white, - ), - onPressed: (){ - if(isPlaying){ - setState(() { - isPlaying = false; - }); - _playerLogic.pauseMusic(); - __animationController.reverse(); - } - else{ - setState(() { - isPlaying = true; - }); - _playerLogic.playPausedMusic(); - //__animationController.forward(); - } - } - ), - IconButton( - icon: Icon( - Icons.fast_forward,color: Colors.white, + Container( + margin: EdgeInsets.fromLTRB(20, 20, 20, 20), + child: Text( + "Library", + style: TextStyle( + color: Colors.white, + fontSize: 27, + fontWeight: FontWeight.bold + ) ), - onPressed: (){ - if(appstate.songinfos!=null && appstate.songinfos.isNotEmpty){ - _playerLogic.nextSong(appstate.songinfos); - //appstatepos.index = appstatepos.index + 1; - } - else - print("error next"); - } ), - ], - ) - ], - ) + ] + ) + ), + ), ) - ), ); } } \ No newline at end of file diff --git a/lib/ux/components/appBars/playerAppBar.dart b/lib/ux/components/appBars/playerAppBar.dart index aac8da5..2d8153d 100644 --- a/lib/ux/components/appBars/playerAppBar.dart +++ b/lib/ux/components/appBars/playerAppBar.dart @@ -16,7 +16,9 @@ class PlayerAppBar extends StatelessWidget { alignment: Alignment.centerLeft, child: IconButton( icon: Icon(Icons.arrow_back_ios), - onPressed: (){Navigator.pop(context);} + onPressed: (){ + Navigator.of(context).pop(); + } ), ) ), diff --git a/lib/ux/components/cards/miniPlayer.dart b/lib/ux/components/cards/miniPlayer.dart new file mode 100644 index 0000000..d03f6fe --- /dev/null +++ b/lib/ux/components/cards/miniPlayer.dart @@ -0,0 +1,182 @@ +import 'dart:async'; +import 'dart:ui'; + +import 'package:Raylex/logic/models/playerStateNotify.dart'; +import 'package:Raylex/logic/models/playlistPosition.dart'; +import 'package:Raylex/logic/models/songInfo.dart'; +import 'package:Raylex/logic/playerLogic.dart'; +import 'package:Raylex/ux/pages/playerUIPage.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_icons/flutter_icons.dart'; +import 'package:provider/provider.dart'; + +class MiniPlayer extends StatefulWidget { + @override + _MiniPlayerState createState() => _MiniPlayerState(); +} + + + +class _MiniPlayerState extends State with SingleTickerProviderStateMixin { + AnimationController _controller; + PlayerStateNotify appstate; + PlaylistPosition appstatepos; + StreamSubscription _streamSubscriptionState; + bool isPlaying; + PlayerLogic _playerLogic; + + @override + void initState() { + super.initState(); + _controller = AnimationController( + vsync: this, + duration: Duration(milliseconds: 300) + ); + _playerLogic = PlayerLogic(); + } + + @override + void didChangeDependencies(){ + super.didChangeDependencies(); + if(appstate==null) + appstate = Provider.of(context); + if(appstatepos==null) + appstatepos = Provider.of(context); + _playerLogic.setMethodCallHandler(); + _streamSubscriptionState = _playerLogic.onPlayerStateChanged.listen((state) { + print("onStateChanged"); + + if(state == PlayerState.PLAYING){ + setState(() { + isPlaying = true; + }); + _controller.forward(); + } + if(state == PlayerState.PAUSED){ + setState(() { + isPlaying = false; + }); + _controller.reverse(); + } + if(state == PlayerState.STOPPED){ + setState(() { + isPlaying = false; + }); + _controller.reverse(); + } + }); + _playerLogic.onInstanceIsPlaying().then((isP) { + setState(() { + isPlaying = isP; + }); + if(isP){ + _controller.forward(from: _controller.upperBound); + } + }); + } + + @override + void dispose() { + super.dispose(); + _controller.dispose(); + _streamSubscriptionState.cancel(); + } + + + onPlayClick(){ + if(isPlaying) + _playerLogic.pauseMusic(); + else + _playerLogic.playPausedMusic(); + } + + + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.fromLTRB(2,0,2,1), + child: ClipRRect( + borderRadius: BorderRadius.circular(10), + child: BackdropFilter( + filter: ImageFilter.blur(sigmaY: 10.0,sigmaX: 10.0), + child: Container( + height: 60, + color: Colors.lightBlue.withAlpha(180), + child: Padding( + padding: const EdgeInsets.fromLTRB(10, 2,10,2), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + flex: 8, + child: GestureDetector( + onTap: (){ + Navigator.of(context).push(MaterialPageRoute(builder: (context)=>PlayerUIPage(_playerLogic))); + }, + child: Container( + width: 180, + margin: EdgeInsets.only(right: 5, left: 5), + child: Text( + appstate.songinfos!=null&&appstatepos.index!=null?appstate.songinfos.elementAt(appstatepos.index).title:"", + overflow: TextOverflow.fade, + softWrap: false, + maxLines: 1, + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + fontSize: 18 + ), + ), + ) + ), + ), + Expanded( + flex: 3, + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + ClipRRect( + borderRadius: BorderRadius.circular(50), + child: Material( + shadowColor: Colors.red, + + color: Colors.transparent, + child: IconButton( + color: Colors.white, + icon: AnimatedIcon( + icon: AnimatedIcons.play_pause, + progress: _controller, + ), + onPressed: ()=>onPlayClick() + ), + ), + ), + ClipRRect( + borderRadius: BorderRadius.circular(50), + child: Material( + shadowColor: Colors.red, + + color: Colors.transparent, + child: IconButton( + color: Colors.white, + icon: Icon(FlutterIcons.fast_forward_mdi), + onPressed: (){ + _playerLogic.nextSong(appstate.songinfos, appstatepos.index); + ++appstatepos.index; + } + ), + ), + ), + ], + ), + ) + ], + ), + ), + ), + ) + ), + ); + } +} \ No newline at end of file diff --git a/lib/ux/components/cards/playerAlbumArtCard.dart b/lib/ux/components/cards/playerAlbumArtCard.dart index e0516ca..f493394 100644 --- a/lib/ux/components/cards/playerAlbumArtCard.dart +++ b/lib/ux/components/cards/playerAlbumArtCard.dart @@ -1,16 +1,14 @@ import 'dart:async'; import 'dart:io'; +import 'package:Raylex/logic/models/playerStateNotify.dart'; +import 'package:Raylex/logic/models/playlistPosition.dart'; import 'package:Raylex/logic/models/songInfo.dart'; import 'package:Raylex/logic/playerLogic.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class PlayerAlbumArtCard extends StatefulWidget { - final List songinfos; - final int index; - final PlayerLogic _playerLogic; - PlayerAlbumArtCard(this.songinfos, this.index, this._playerLogic); - @override _PlayerAlbumArtCardState createState() => _PlayerAlbumArtCardState(); } @@ -18,22 +16,16 @@ class PlayerAlbumArtCard extends StatefulWidget { class _PlayerAlbumArtCardState extends State { StreamSubscription _playlistPositionSubscription; - int index; @override void initState(){ super.initState(); - index = widget.index; } @override void didChangeDependencies(){ super.didChangeDependencies(); - _playlistPositionSubscription = widget._playerLogic.onPlaylistPositionChanged.listen((pos) { - setState(() { - index = pos; - }); - }); + } @override @@ -44,6 +36,8 @@ class _PlayerAlbumArtCardState extends State { @override Widget build(BuildContext context) { + var appstatelist = Provider.of(context); + var appstatepos = Provider.of(context); return Container( margin: EdgeInsets.fromLTRB(0, 5, 0, 5), decoration: BoxDecoration( @@ -64,7 +58,7 @@ class _PlayerAlbumArtCardState extends State { child: Container( color: Colors.white, child: Image( - image: widget.songinfos.elementAt(index).albumArt!=null?FileImage(File(widget.songinfos.elementAt(index).albumArt)):AssetImage("lib/assets/images/white-headphone.jpg"), + image: appstatelist.songinfos!=null&&appstatelist.songinfos.elementAt(appstatepos.index).albumArt!=null?FileImage(File(appstatelist.songinfos.elementAt(appstatepos.index).albumArt)):AssetImage("lib/assets/images/white-headphone.jpg"), fit: BoxFit.cover, ), ), diff --git a/lib/ux/components/groups/groupPlayerControl.dart b/lib/ux/components/groups/groupPlayerControl.dart index a92b514..dc88d80 100644 --- a/lib/ux/components/groups/groupPlayerControl.dart +++ b/lib/ux/components/groups/groupPlayerControl.dart @@ -8,11 +8,9 @@ import 'package:flutter_icons/flutter_icons.dart'; import 'package:provider/provider.dart'; class GroupPlayerControl extends StatefulWidget { - final List songinfos; - final int index; final PlayerLogic _playerLogic; - GroupPlayerControl(this.songinfos, this.index, this._playerLogic); + GroupPlayerControl(this._playerLogic); @override _GroupPlayerControlState createState() => _GroupPlayerControlState(); } @@ -22,35 +20,34 @@ class _GroupPlayerControlState extends State with TickerProv Duration _audioDuration = Duration(); AnimationController _animationController; bool isPlaying = false; - int index; - //PlayerStateNotify appstate; - PlaylistPosition appstate; StreamSubscription _subscriptionAudioPositionChanged; StreamSubscription _subscriptionPlayerStateChanged; StreamSubscription _subscriptionAudioDurationChanged; + PlaylistPosition appstatepos; + PlayerStateNotify appstatelist; @override void didChangeDependencies(){ super.didChangeDependencies(); print("player didchangeddependencies"); - print("initial $_audioDuration"); - appstate = Provider.of(context); - appstate.index = index; + print("initial $_audioDuration"); + appstatepos = Provider.of(context); + appstatelist = Provider.of(context); + _subscriptionAudioPositionChanged = widget._playerLogic.onAudioPositionChanged.listen((pos) { setState(() { _playerSeekValue = pos; }); }); _subscriptionAudioDurationChanged = widget._playerLogic.onDurationChanged.listen((duration) { + print(duration.inMilliseconds.toString()); setState(() { - print(duration.inMilliseconds.toString()); if(duration != Duration.zero) _audioDuration = duration; }); }); _subscriptionPlayerStateChanged = widget._playerLogic.onPlayerStateChanged.listen((state) { print("onStateChanged"); - if(state == PlayerState.PLAYING){ setState(() { isPlaying = true; @@ -71,8 +68,7 @@ class _GroupPlayerControlState extends State with TickerProv print("song stopped at ${_playerSeekValue.inSeconds} of ${_audioDuration.inSeconds}"); if(_playerSeekValue.inSeconds == _audioDuration.inSeconds){ print("song ended"); - widget._playerLogic.nextSong(widget.songinfos); - ++index; + widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index); } } }); @@ -97,11 +93,8 @@ class _GroupPlayerControlState extends State with TickerProv vsync: this, duration: Duration(milliseconds: 300), ); - if(!isPlaying){ - widget._playerLogic.playMusic(widget.songinfos.elementAt(widget.index).uri); - } - index = widget.index; - widget._playerLogic.setPlaylistPostion(index); + + //widget._playerLogic.setPlaylistPostion(index); } @override @@ -196,9 +189,8 @@ class _GroupPlayerControlState extends State with TickerProv color: Colors.grey.shade600, ), onPressed: (){ - widget._playerLogic.prevSong(widget.songinfos); - --index; - appstate.index = index; + widget._playerLogic.prevSong(appstatelist.songinfos, appstatepos.index); + --appstatepos.index; }, ), IconButton( @@ -214,8 +206,8 @@ class _GroupPlayerControlState extends State with TickerProv widget._playerLogic.pauseMusic(); } else{ - widget._playerLogic.playMusic(widget.songinfos.elementAt(index).uri); - appstate.index = index; + widget._playerLogic.playMusic(appstatelist.songinfos.elementAt(appstatepos.index).uri); + //appstate.index = index; } }, ), @@ -227,9 +219,8 @@ class _GroupPlayerControlState extends State with TickerProv color: Colors.grey.shade600, ), onPressed: (){ - widget._playerLogic.nextSong(widget.songinfos); - ++index; - appstate.index = index; + widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index); + ++appstatepos.index; } ) ], diff --git a/lib/ux/components/groups/groupPlayerTextMeta.dart b/lib/ux/components/groups/groupPlayerTextMeta.dart index 50ca7f0..8e37a30 100644 --- a/lib/ux/components/groups/groupPlayerTextMeta.dart +++ b/lib/ux/components/groups/groupPlayerTextMeta.dart @@ -1,49 +1,42 @@ import 'dart:async'; +import 'package:Raylex/logic/models/playerStateNotify.dart'; +import 'package:Raylex/logic/models/playlistPosition.dart'; import 'package:Raylex/logic/models/songInfo.dart'; import 'package:Raylex/logic/playerLogic.dart'; import 'package:Raylex/ux/components/animations/marqueeWidget.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; class GroupPlayerTextMeta extends StatefulWidget { - final List songinfos; - final int index; - final PlayerLogic _playerLogic; - GroupPlayerTextMeta(this.songinfos, this.index, this._playerLogic); @override _GroupPlayerTextMetaState createState() => _GroupPlayerTextMetaState(); } class _GroupPlayerTextMetaState extends State { - StreamSubscription _playlistPositionSubscription; - int index; + @override void initState(){ super.initState(); - index = widget.index; } @override void didChangeDependencies(){ super.didChangeDependencies(); - _playlistPositionSubscription = widget._playerLogic.onPlaylistPositionChanged.listen((pos) { - print("playertext playlist pos changed"); - setState(() { - index = pos; - }); - }); + } @override void dispose(){ super.dispose(); - _playlistPositionSubscription.cancel(); } @override Widget build(BuildContext context) { + var appstatelist = Provider.of(context); + var appstatepos = Provider.of(context); return Column( children: [ Container( @@ -51,7 +44,8 @@ class _GroupPlayerTextMetaState extends State { alignment: Alignment.centerLeft, child: MarqueeWidget( child: Text( - widget.songinfos.elementAt(index).title, + appstatelist.songinfos!=null? + appstatelist.songinfos.elementAt(appstatepos.index).title:"", style: TextStyle( color: Colors.deepPurple, fontSize: 28, @@ -65,7 +59,8 @@ class _GroupPlayerTextMetaState extends State { alignment: Alignment.centerLeft, child: MarqueeWidget( child: Text( - widget.songinfos.elementAt(index).artist.toUpperCase(), + appstatelist.songinfos!=null? + appstatelist.songinfos.elementAt(appstatepos.index).artist.toUpperCase():"", style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold diff --git a/lib/ux/components/lists/verticalListSimple.dart b/lib/ux/components/lists/verticalListSimple.dart index b509ba1..fac0ae8 100644 --- a/lib/ux/components/lists/verticalListSimple.dart +++ b/lib/ux/components/lists/verticalListSimple.dart @@ -66,10 +66,8 @@ class _VerticalListSimpleState extends State { return Text(""); }()), onTap: (){ - Navigator.push( - context, - MaterialPageRoute(builder: (context) => PlayerUIPage(widget.songinfo, index)) - ); + PlayerLogic().playMusic(widget.songinfo.elementAt(index).uri); + appstate.index = index; setState(() { currentPlaying = index; }); diff --git a/lib/ux/pages/libraryPages.dart b/lib/ux/pages/libraryPages.dart index 12dbbec..0d4acca 100644 --- a/lib/ux/pages/libraryPages.dart +++ b/lib/ux/pages/libraryPages.dart @@ -13,10 +13,15 @@ class LibraryPages extends StatefulWidget { } class _LibraryPagesState extends State { - + PlayerStateNotify appstate; + @override + void didChangeDependencies(){ + super.didChangeDependencies(); + if(appstate==null) + appstate=Provider.of(context); + } @override Widget build(BuildContext context) { - var appstate=Provider.of(context); return Column( children: [ LibraryAppBar(), diff --git a/lib/ux/pages/navPages.dart b/lib/ux/pages/navPages.dart index c798c69..f4043f6 100644 --- a/lib/ux/pages/navPages.dart +++ b/lib/ux/pages/navPages.dart @@ -1,9 +1,15 @@ +import 'package:Raylex/logic/models/modelMiniplayer.dart'; +import 'package:Raylex/logic/models/playerStateNotify.dart'; +import 'package:Raylex/logic/models/playlistPosition.dart'; +import 'package:Raylex/ux/components/cards/miniPlayer.dart'; import 'package:Raylex/ux/pages/historyPage.dart'; import 'package:Raylex/ux/pages/libraryPages.dart'; import 'package:Raylex/ux/pages/likedPage.dart'; +import 'package:Raylex/ux/pages/playerUIPage.dart'; import 'package:Raylex/ux/pages/searchPage.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; //nav pages class NavPages extends StatefulWidget { @@ -15,19 +21,32 @@ class NavPages extends StatefulWidget { class _NavPagesState extends State { //the default index and initialising index of the nav bar int _currentIndex = 0; + + @override + void didChangeDependencies(){ + super.didChangeDependencies(); + } + @override Widget build(BuildContext context) { return Scaffold( extendBody: false, + backgroundColor: Colors.white, //body of the nav bar - body: IndexedStack( - index: _currentIndex, - //the body of the nav should be here index wise + body: Stack( + alignment: Alignment.bottomCenter, children: [ - LibraryPages(), - LikedPage(), - HistoryPage(), - SearchPage() + IndexedStack( + index: _currentIndex, + //the body of the nav should be here index wise + children: [ + LibraryPages(), + LikedPage(), + HistoryPage(), + SearchPage() + ], + ), + MiniPlayer() ], ), //nav bar @@ -45,7 +64,7 @@ class _NavPagesState extends State { currentIndex: _currentIndex, selectedFontSize: 12, iconSize: 40, - backgroundColor: Colors.lightBlue, + backgroundColor: Colors.lightBlue.withAlpha(200), selectedItemColor: Colors.white, unselectedItemColor: Colors.white70, type: BottomNavigationBarType.fixed, diff --git a/lib/ux/pages/playerUIPage.dart b/lib/ux/pages/playerUIPage.dart index ce8b6f6..c77b001 100644 --- a/lib/ux/pages/playerUIPage.dart +++ b/lib/ux/pages/playerUIPage.dart @@ -1,45 +1,76 @@ +import 'dart:ui'; + +import 'package:Raylex/logic/models/modelMiniplayer.dart'; +import 'package:Raylex/logic/models/playerStateNotify.dart'; +import 'package:Raylex/logic/models/playlistPosition.dart'; import 'package:Raylex/logic/models/songInfo.dart'; import 'package:Raylex/logic/playerLogic.dart'; import 'package:Raylex/ux/components/appBars/playerAppBar.dart'; +import 'package:Raylex/ux/components/cards/miniPlayer.dart'; import 'package:Raylex/ux/components/cards/playerAlbumArtCard.dart'; import 'package:Raylex/ux/components/groups/groupPlayerAccControl.dart'; import 'package:Raylex/ux/components/groups/groupPlayerControl.dart'; import 'package:Raylex/ux/components/groups/groupPlayerTextMeta.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_icons/flutter_icons.dart'; +import 'package:provider/provider.dart'; + +class PlayerUIPage extends StatefulWidget{ + final PlayerLogic _playerLogic; + PlayerUIPage(this._playerLogic); + @override + _PlayerUIPageState createState() => _PlayerUIPageState(); +} + +class _PlayerUIPageState extends State { + PlayerStateNotify appstate; + PlaylistPosition appstatepos; + //bool miniplayer=true; + + + + @override + void initState(){ + super.initState(); + } + + @override + void didChangeDependencies(){ + super.didChangeDependencies(); + appstate = Provider.of(context); + appstatepos = Provider.of(context); + } + + @override + void dispose(){ + super.dispose(); + } -class PlayerUIPage extends StatelessWidget{ - final List songInfos; - final index; - final PlayerLogic _playerLogic = PlayerLogic(); - PlayerUIPage(this.songInfos, this.index); @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.white, - body: Container( - //any decoration should declare here - decoration: BoxDecoration( - - ), + return Container( child: SafeArea( - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - //the top portion playlist name, back, menu consist here - PlayerAppBar(), - //the album art is consist here - PlayerAlbumArtCard(songInfos, index, _playerLogic), - //song name and artist name here - GroupPlayerTextMeta(songInfos, index, _playerLogic), - //basics controls like seek, play pause, next, previous - GroupPlayerControl(songInfos, index, _playerLogic), - //acco controls like mute speaker of headset set shuffle and repeats - GroupPlayerAccControl(), - ], - ) + child: + Scaffold( + backgroundColor: Colors.white, + body: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + //the top portion playlist name, back, menu consist here + PlayerAppBar(), + //the album art is consist here + PlayerAlbumArtCard(), + //song name and artist name here + GroupPlayerTextMeta(), + //basics controls like seek, play pause, next, previous + GroupPlayerControl(widget._playerLogic), + //acco controls like mute speaker of headset set shuffle and repeats + GroupPlayerAccControl(), + ], + ), + ) ), - ), - ); + ); } } \ No newline at end of file