Skip to content

Commit

Permalink
new album art, used universal font, fixed playlist-order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
o-ifeanyi committed Sep 24, 2020
1 parent c85f9e9 commit 47554d3
Show file tree
Hide file tree
Showing 19 changed files with 495 additions and 446 deletions.
Binary file added images/album_art.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/album_art.png
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/components/circleDisc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class _CircleDiscState extends State<CircleDisc>
borderRadius: BorderRadius.circular(10),
image: DecorationImage(
image: controller.songArt == null
? AssetImage('images/album_art.png')
? AssetImage('images/album_art.jpg')
: MemoryImage(controller.songArt),
fit: BoxFit.cover,
),
Expand Down
36 changes: 21 additions & 15 deletions lib/components/createPlayList.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ class _CreatePlayListState extends State<CreatePlayList> {
bool createNew;
String playlistName;
TextEditingController inputFeild = TextEditingController();

void createPlaylist() {
if (inputFeild.text != '') {
playlistName = inputFeild.text;
Provider.of<PlayListDB>(context, listen: false)
.createPlaylist(playlistName);
Navigator.pop(context);
} else {
print('empty feild');
}
}

@override
void initState() {
createNew = widget.isCreateNew;
Expand All @@ -42,9 +54,9 @@ class _CreatePlayListState extends State<CreatePlayList> {
Orientation orientation = MediaQuery.of(context).orientation;
Size viewsSize = MediaQuery.of(context).size;
TextStyle textStyle = TextStyle(
fontSize: Config.textSize(context, 4),
fontWeight: FontWeight.w400,
fontFamily: 'Acme');
fontSize: Config.textSize(context, 4),
fontWeight: FontWeight.w400,
);

return Container(
height: orientation == Orientation.portrait
Expand Down Expand Up @@ -91,10 +103,12 @@ class _CreatePlayListState extends State<CreatePlayList> {
TextField(
controller: inputFeild,
keyboardType: TextInputType.name,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
labelText: 'Name',
labelStyle: textStyle,
),
onSubmitted: (_) => createPlaylist(),
),
],
),
Expand All @@ -118,7 +132,9 @@ class _CreatePlayListState extends State<CreatePlayList> {
.setFavourite(song);
}
});
Provider.of<ShareClass>(context, listen: false).reset(notify: true);
Provider.of<ShareClass>(context,
listen: false)
.reset(notify: true);
Navigator.pop(context);
},
child: index > 0 &&
Expand Down Expand Up @@ -146,17 +162,7 @@ class _CreatePlayListState extends State<CreatePlayList> {
),
createNew
? FlatButton(
onPressed: () {
if (inputFeild.text != '') {
playlistName = inputFeild.text;
Provider.of<PlayListDB>(context,
listen: false)
.createPlaylist(playlistName);
Navigator.pop(context);
} else {
print('empty feild');
}
},
onPressed: createPlaylist,
child: Text(
'Create playlist',
style: textStyle,
Expand Down
10 changes: 5 additions & 5 deletions lib/components/customCard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ class CustomCard extends StatelessWidget {
Text(
label,
style: TextStyle(
fontSize: Config.textSize(context, 3.5),
fontWeight: FontWeight.w400,
fontFamily: 'Acme'),
fontSize: Config.textSize(context, 3.5),
fontWeight: FontWeight.w400,
),
),
],
),
numOfSongs != null
? Text(
'$numOfSongs Songs',
style: TextStyle(
fontSize: Config.textSize(context, 3),
fontFamily: 'Acme'),
fontSize: Config.textSize(context, 3),
),
)
: SizedBox.shrink(),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/components/libraryBottomSheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class LibraryBottomSheet extends StatelessWidget {
LibraryBottomSheet(this.playlistName);
final playlistName;
final editingController = TextEditingController();

@override
Widget build(BuildContext context) {
TextStyle customTextStyle = TextStyle(
fontSize: Config.textSize(context, 3.5),
fontWeight: FontWeight.w400,
fontFamily: 'Acme',
);
return Container(
height: Config.yMargin(context, 10),
Expand Down
1 change: 0 additions & 1 deletion lib/components/playlistOptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class PlaylistOptions extends StatelessWidget {
TextStyle customTextStyle = TextStyle(
fontSize: Config.textSize(context, 3.5),
fontWeight: FontWeight.w400,
fontFamily: 'Acme',
);
return Container(
height: 70,
Expand Down
97 changes: 97 additions & 0 deletions lib/components/popupButton.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import 'package:flutter/material.dart';
import 'package:musicPlayer/models/config.dart';
import 'package:musicPlayer/models/songController.dart';
import 'package:share/share.dart';
import 'createPlayList.dart';

class PopUpButton extends StatelessWidget {
PopUpButton({
@required this.songList,
@required this.canDelete,
@required this.index,
@required this.controller,
@required this.dialogFunction,
});

final List songList;
final bool canDelete;
final SongController controller;
final Function dialogFunction;
final int index;

@override
Widget build(BuildContext context) {
TextStyle customTextStyle = TextStyle(
fontSize: Config.textSize(context, 3.5),
fontWeight: FontWeight.w400,
fontFamily: 'Acme');

return PopupMenuButton(
icon: Icon(
Icons.more_vert,
size: Config.xMargin(context, 6),
),
itemBuilder: (context) {
return <PopupMenuEntry<ListTile>>[
PopupMenuItem(
child: ListTile(
dense: true,
trailing: Icon(Icons.playlist_add),
title: Text(
'Add to playlist',
style: customTextStyle,
),
onTap: () async {
Navigator.pop(context);
showDialog(
context: context,
builder: (context) {
return CreatePlayList(
height: 35,
width: 35,
songs: [songList[index]],
isCreateNew: false,
);
},
);
},
),
),
PopupMenuItem(
child: ListTile(
dense: true,
trailing: Icon(canDelete ? Icons.delete : Icons.remove),
onTap: () async {
Navigator.pop(context);
await dialogFunction(context, songList, index, controller);
},
title: Text(
canDelete ? 'Delete song' : 'Remove song',
// textAlign: TextAlign.left,
style: customTextStyle,
),
),
),
PopupMenuItem(
child: ListTile(
dense: true,
trailing: Icon(Icons.share),
title: Text(
'Share',
style: customTextStyle,
),
onTap: () async {
final RenderBox box = context.findRenderObject();
Navigator.pop(context);
await Share.shareFiles([songList[index]['path']],
subject: songList[index]['title'],
sharePositionOrigin:
box.localToGlobal(Offset.zero) & box.size);
},
),
)
];
},
);
}
}
4 changes: 4 additions & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final List kThemes = [
backgroundColor: Colors.white,
scaffoldBackgroundColor: Colors.grey[100],
dividerColor: Colors.black45,
fontFamily: 'Acme',
iconTheme: IconThemeData(
color: Colors.black,
opacity: 0.8,
Expand All @@ -33,6 +34,7 @@ final List kThemes = [
backgroundColor: Colors.white,
scaffoldBackgroundColor: Colors.grey[100],
dividerColor: Colors.black45,
fontFamily: 'Acme',
iconTheme: IconThemeData(
color: Colors.black,
opacity: 0.8,
Expand All @@ -55,6 +57,7 @@ final List kThemes = [
accentColor: Colors.pinkAccent,
cursorColor: Colors.pinkAccent,
dividerColor: Colors.white54,
fontFamily: 'Acme',
sliderTheme: SliderThemeData(
trackHeight: 1.0,
thumbColor: Colors.pinkAccent,
Expand All @@ -73,6 +76,7 @@ final List kThemes = [
accentColor: Colors.deepOrange,
cursorColor: Colors.deepOrange,
dividerColor: Colors.white54,
fontFamily: 'Acme',
sliderTheme: SliderThemeData(
trackHeight: 1.0,
thumbColor: Colors.deepOrange,
Expand Down
3 changes: 3 additions & 0 deletions lib/models/Provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class ProviderClass extends ChangeNotifier {
Future<void> getAllSongs() async {
PermissionStatus permissionStatus = await Permission.storage.request();
if (permissionStatus.isGranted && Platform.isAndroid) {
// externalStorageDirectories includes:
// /storage/emulated/0/Android/data/com.onuifeanyi.vybeplayer/files
// /storage/1A1C-1205/Android/data/com.onuifeanyi.vybeplayer/files
List<Directory> deviceStorages = await getExternalStorageDirectories();
List<Directory> pathToStorage = [];
for (var dir in deviceStorages) {
Expand Down
20 changes: 15 additions & 5 deletions lib/models/playListDB.dart
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ class PlayListDB extends ChangeNotifier {
Future<void> saveNowPlaying(dynamic song) async {
Box db = await Hive.openBox('recent', path: await getRecentPath());
List songs = db.get('Recently played');
bool notFound = songs.every((element) => element['path'] != song['path']);
if (notFound && songs.length < 20) {
bool found = songs.any((element) => element['path'] == song['path']);
if (!found && songs.length < 20) {
songs.add(song);
} else if (notFound && songs.length == 20) {
} else if (!found && songs.length == 20) {
songs.removeAt(0);
songs.add(song);
} else if (found) {
songs.removeWhere((element) => element['path'] == song['path']);
songs.add(song);
}
db.put('Recently played', songs);
}
Expand All @@ -124,7 +127,8 @@ class PlayListDB extends ChangeNotifier {
if (songs.isNotEmpty) {
recentList.clear();
for (var each in songs) {
recentList.add(each);
// most recent song to be at the top
recentList.insert(0, each);
}
}
notifyListeners();
Expand Down Expand Up @@ -162,7 +166,13 @@ class PlayListDB extends ChangeNotifier {
if (db.values.length != 0) {
playList.clear();
for (var each in db.values) {
playList.add(each);
if (each['name'] == 'Create playlist') {
playList.insert(0, each);
} else if (each['name'] == 'Favourites') {
playList.insert(1, each);
} else {
playList.add(each);
}
}
await getRecentlyPlayed();
} else {
Expand Down
23 changes: 13 additions & 10 deletions lib/models/songController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ class SongController extends ChangeNotifier {
pref.setBool('useArt', value);
});
useArt = value;
if (nowPlaying['path'] != null) {
songArt = await Audiotagger().readArtwork(path: nowPlaying['path']);
if (nowPlaying['path'] != null && useArt) {
await Audiotagger().readArtwork(path: nowPlaying['path']).then((value) {
songArt = value;
}).catchError((e) => print(e));
}
notifyListeners();
}
Expand All @@ -68,7 +70,9 @@ class SongController extends ChangeNotifier {
songLenght = duration.inSeconds;
timeLeft = '${duration.inMinutes}:${duration.inSeconds % 60}';
if (useArt) {
songArt = await Audiotagger().readArtwork(path: song['path']);
await Audiotagger().readArtwork(path: nowPlaying['path']).then((value) {
songArt = value;
}).catchError((e) => print(e));
}
isFavourite = await playListDB.isFavourite(nowPlaying);
playListDB.saveNowPlaying(nowPlaying);
Expand Down Expand Up @@ -107,8 +111,7 @@ class SongController extends ChangeNotifier {
await player.seek(Duration(seconds: currentTime + position.toInt()));
}

Future<void> skip(
{bool next = false, bool prev = false}) async {
Future<void> skip({bool next = false, bool prev = false}) async {
currentSongIndex =
allSongs.indexWhere((element) => element['path'] == nowPlaying['path']);
List shuffled = [...allSongs];
Expand Down Expand Up @@ -159,11 +162,11 @@ class SongController extends ChangeNotifier {

Future<void> disposePlayer() async {
try {
if (player.playbackState == AudioPlaybackState.playing ||
player.playbackState == AudioPlaybackState.paused) {
await player.dispose();
}
} catch(e) {
if (player.playbackState == AudioPlaybackState.playing ||
player.playbackState == AudioPlaybackState.paused) {
await player.dispose();
}
} catch (e) {
debugPrint(e.toString());
}
setIsPlaying(false);
Expand Down
Loading

0 comments on commit 47554d3

Please sign in to comment.