Skip to content

Commit

Permalink
fixes some state issue, library song list load into appstate is still…
Browse files Browse the repository at this point in the history
… give issue warning
  • Loading branch information
raysummee committed Jul 3, 2020
1 parent 871d694 commit 8a64fc7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 155 deletions.
2 changes: 1 addition & 1 deletion lib/logic/models/playerStateNotify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PlayerStateNotify with ChangeNotifier{

List<SongInfo> get songinfos => _songinfos;

set songInfos(List<SongInfo> songinfolist){
set songinfos(List<SongInfo> songinfolist){
_songinfos = songinfolist;
notifyListeners();
}
Expand Down
61 changes: 35 additions & 26 deletions lib/ux/components/cards/miniPlayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class MiniPlayer extends StatefulWidget {

class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateMixin {
AnimationController _controller;
PlayerStateNotify appstate;
PlaylistPosition appstatepos;
StreamSubscription _streamSubscriptionState;
bool isPlaying;
PlayerLogic _playerLogic;
Expand All @@ -38,39 +36,43 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM
@override
void didChangeDependencies(){
super.didChangeDependencies();
if(appstate==null)
appstate = Provider.of<PlayerStateNotify>(context);
if(appstatepos==null)
appstatepos = Provider.of<PlaylistPosition>(context);
_playerLogic.setMethodCallHandler();
_streamSubscriptionState = _playerLogic.onPlayerStateChanged.listen((state) {
print("onStateChanged");

if(state == PlayerState.PLAYING){
setState(() {
isPlaying = true;
});
_controller.forward();
if(mounted){
setState(() {
isPlaying = true;
});
_controller.forward();
}
}
if(state == PlayerState.PAUSED){
setState(() {
isPlaying = false;
});
_controller.reverse();
if(mounted){
setState(() {
isPlaying = false;
});
_controller.reverse();
}
}
if(state == PlayerState.STOPPED){
setState(() {
isPlaying = false;
});
_controller.reverse();
if(mounted){
setState(() {
isPlaying = false;
});
_controller.reverse();
}
}
});
_playerLogic.onInstanceIsPlaying().then((isP) {
setState(() {
isPlaying = isP;
});
if(isP){
_controller.forward(from: _controller.upperBound);
if(mounted){
setState(() {
isPlaying = isP;
});
if(isP){
_controller.forward(from: _controller.upperBound);
}
}
});
}
Expand All @@ -94,6 +96,8 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM

@override
Widget build(BuildContext context) {
var appstate = Provider.of<PlayerStateNotify>(context);
var appstatepos = Provider.of<PlaylistPosition>(context);
return Padding(
padding: const EdgeInsets.fromLTRB(2,0,2,1),
child: ClipRRect(
Expand Down Expand Up @@ -148,7 +152,10 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM
icon: AnimatedIcons.play_pause,
progress: _controller,
),
onPressed: ()=>onPlayClick()
onPressed: (){
if(appstate.songinfos!=null&&appstatepos.index!=null)
onPlayClick();
}
),
),
),
Expand All @@ -162,8 +169,10 @@ class _MiniPlayerState extends State<MiniPlayer> with SingleTickerProviderStateM
color: Colors.white,
icon: Icon(FlutterIcons.fast_forward_mdi),
onPressed: (){
_playerLogic.nextSong(appstate.songinfos, appstatepos.index);
++appstatepos.index;
if(appstate.songinfos!=null&&appstatepos!=null){
_playerLogic.nextSong(appstate.songinfos, appstatepos.index);
++appstatepos.index;
}
}
),
),
Expand Down
25 changes: 1 addition & 24 deletions lib/ux/components/cards/playerAlbumArtCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,8 @@ import 'package:Raylex/logic/playerLogic.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PlayerAlbumArtCard extends StatefulWidget {
@override
_PlayerAlbumArtCardState createState() => _PlayerAlbumArtCardState();
}

class _PlayerAlbumArtCardState extends State<PlayerAlbumArtCard> {

StreamSubscription _playlistPositionSubscription;

@override
void initState(){
super.initState();
}

@override
void didChangeDependencies(){
super.didChangeDependencies();

}

@override
void dispose(){
super.dispose();
_playlistPositionSubscription.cancel();
}
class PlayerAlbumArtCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
Expand Down
59 changes: 36 additions & 23 deletions lib/ux/components/groups/groupPlayerControl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,26 @@ class _GroupPlayerControlState extends State<GroupPlayerControl> with TickerProv
StreamSubscription _subscriptionAudioPositionChanged;
StreamSubscription _subscriptionPlayerStateChanged;
StreamSubscription _subscriptionAudioDurationChanged;
PlaylistPosition appstatepos;
PlayerStateNotify appstatelist;
//PlaylistPosition appstatepos;
//PlayerStateNotify appstatelist;

@override
void didChangeDependencies(){
super.didChangeDependencies();
print("player didchangeddependencies");
print("initial $_audioDuration");
appstatepos = Provider.of<PlaylistPosition>(context);
appstatelist = Provider.of<PlayerStateNotify>(context);
final appstatepos = Provider.of<PlaylistPosition>(context, listen: false);
final appstatelist = Provider.of<PlayerStateNotify>(context, listen: false);

_subscriptionAudioPositionChanged = widget._playerLogic.onAudioPositionChanged.listen((pos) {
if(mounted)
setState(() {
_playerSeekValue = pos;
});
});
_subscriptionAudioDurationChanged = widget._playerLogic.onDurationChanged.listen((duration) {
print(duration.inMilliseconds.toString());
if(mounted)
setState(() {
if(duration != Duration.zero)
_audioDuration = duration;
Expand All @@ -49,36 +51,45 @@ class _GroupPlayerControlState extends State<GroupPlayerControl> with TickerProv
_subscriptionPlayerStateChanged = widget._playerLogic.onPlayerStateChanged.listen((state) {
print("onStateChanged");
if(state == PlayerState.PLAYING){
setState(() {
isPlaying = true;
});
_animationController.forward();
if(mounted){
setState(() {
isPlaying = true;
});
_animationController.forward();
}
}
if(state == PlayerState.PAUSED){
setState(() {
isPlaying = false;
});
_animationController.reverse();
if(mounted){
setState(() {
isPlaying = false;
});
_animationController.reverse();
}
}
if(state == PlayerState.STOPPED){
setState(() {
isPlaying = false;
});
_animationController.reverse();
print("song stopped at ${_playerSeekValue.inSeconds} of ${_audioDuration.inSeconds}");
if(_playerSeekValue.inSeconds == _audioDuration.inSeconds){
print("song ended");
widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
if(mounted){
setState(() {
isPlaying = false;
});
_animationController.reverse();
print("song stopped at ${_playerSeekValue.inSeconds} of ${_audioDuration.inSeconds}");
if(_playerSeekValue.inSeconds == _audioDuration.inSeconds){
print("song ended");
widget._playerLogic.nextSong(appstatelist.songinfos, appstatepos.index);
++appstatepos.index;
}
}
}
});
widget._playerLogic.onInstanceIsPlaying().then((isP) {
setState(() {
isPlaying = isP;
if(mounted){
setState(() {
isPlaying = isP;
});
if(isP){
_animationController.forward(from: _animationController.upperBound);
}
});
}
});

}
Expand Down Expand Up @@ -115,6 +126,8 @@ class _GroupPlayerControlState extends State<GroupPlayerControl> with TickerProv

@override
Widget build(BuildContext context) {
var appstatelist = Provider.of<PlayerStateNotify>(context);
var appstatepos = Provider.of<PlaylistPosition>(context);
return Column(
children: <Widget>[
Container(
Expand Down
24 changes: 1 addition & 23 deletions lib/ux/components/groups/groupPlayerTextMeta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,8 @@ import 'package:Raylex/ux/components/animations/marqueeWidget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class GroupPlayerTextMeta extends StatefulWidget {

@override
_GroupPlayerTextMetaState createState() => _GroupPlayerTextMetaState();
}

class _GroupPlayerTextMetaState extends State<GroupPlayerTextMeta> {


@override
void initState(){
super.initState();
}

@override
void didChangeDependencies(){
super.didChangeDependencies();

}

@override
void dispose(){
super.dispose();
}
class GroupPlayerTextMeta extends StatelessWidget {

@override
Widget build(BuildContext context) {
Expand Down
23 changes: 3 additions & 20 deletions lib/ux/components/lists/verticalListSimple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,11 @@ class VerticalListSimple extends StatefulWidget {
}

class _VerticalListSimpleState extends State<VerticalListSimple> {
int currentPlaying;
PlaylistPosition appstate;
@override
void initState(){
super.initState();
}
@override
void didChangeDependencies(){
super.didChangeDependencies();
if(appstate==null)
appstate = Provider.of<PlaylistPosition>(context);
}
@override
void dispose(){
super.dispose();
}

@override
Widget build(BuildContext context) {
var appstate = Provider.of<PlaylistPosition>(context);

return Expanded(
child: ListView.builder(
itemCount: widget.songinfo.length,
Expand All @@ -60,17 +47,13 @@ class _VerticalListSimpleState extends State<VerticalListSimple> {
return Icon(
Icons.bubble_chart,
color: Colors.pink.shade300,

);
else
return Text("");
}()),
onTap: (){
PlayerLogic().playMusic(widget.songinfo.elementAt(index).uri);
appstate.index = index;
setState(() {
currentPlaying = index;
});
}
);
},
Expand Down
11 changes: 3 additions & 8 deletions lib/ux/pages/libraryPages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,10 @@ class LibraryPages extends StatefulWidget {
}

class _LibraryPagesState extends State<LibraryPages> {
PlayerStateNotify appstate;
@override
void didChangeDependencies(){
super.didChangeDependencies();
if(appstate==null)
appstate=Provider.of<PlayerStateNotify>(context);
}

@override
Widget build(BuildContext context) {
var appstate = Provider.of<PlayerStateNotify>(context);
return Column(
children: <Widget>[
LibraryAppBar(),
Expand All @@ -30,7 +25,7 @@ class _LibraryPagesState extends State<LibraryPages> {
builder: (context, snap){
if(snap.data!=null){
List<SongInfo> list = snap.data;
appstate.songInfos = list;
appstate.songinfos = list;
return list.isNotEmpty?VerticalListSimple(list):Expanded(
child: Center(
child: Text("No songs found"),
Expand Down
Loading

0 comments on commit 8a64fc7

Please sign in to comment.