Skip to content

Commit

Permalink
all local songs load perfectly now
Browse files Browse the repository at this point in the history
  • Loading branch information
raysummee committed Jun 25, 2020
1 parent 7219278 commit a4759f8
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void prepare() {
int idColumn = cur.getColumnIndex(MediaStore.Audio.Media._ID);
int trackIdColumn = cur.getColumnIndex(MediaStore.Audio.Media.TRACK);

String musicDirPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
//String musicDirPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
do {
String trackIdStr = cur.getString(trackIdColumn);
int trackId = 0;
Expand All @@ -70,10 +70,11 @@ public void prepare() {
mAudioPath.get(cur.getLong(idColumn)),
mAlbumMap.get(cur.getLong(albumArtColumn)),
trackId);
if (song.uri.startsWith(musicDirPath)) {
//if (song.uri.startsWith(musicDirPath)) {
mSongs.add(song);
}
//}
} while (cur.moveToNext());
cur.close();

}

Expand All @@ -84,6 +85,7 @@ private void loadAlbumArt() {
null,
null);

assert cursor != null;
if (cursor.moveToFirst()) {
do {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Albums._ID));
Expand All @@ -101,6 +103,7 @@ private void loadAudioPath() {
null,
null);

assert cursor != null;
if (cursor.moveToFirst()) {
do {
long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media._ID));
Expand Down Expand Up @@ -195,6 +198,7 @@ public String getURI() {

Cursor mediaCursor = getContentResolver().query(mediaContentUri, projection, selection, selectionArgs, null);

assert mediaCursor != null;
if(mediaCursor.getCount() >= 0) {
mediaCursor.moveToPosition(0);
// String title = mediaCursor.getString(mediaCursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
Expand Down Expand Up @@ -224,6 +228,7 @@ public String getAlbumArt() {
new String[] {String.valueOf(albumId)},
null);

assert cursor != null;
if (cursor.moveToFirst()) {
path = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Albums.ALBUM_ART));
// do whatever you need to do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ public void playPausedMusic(){
}
}

public int getSessionIdMusic(){
if(exoPlayer!=null){
return exoPlayer.getAudioSessionId();
}else{
return 101;
}
}


private final Runnable sendData = new Runnable(){
public void run(){
Expand Down Expand Up @@ -175,6 +183,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull MethodChannel.Result
case "playPausedMusic":
playPausedMusic();
break;
case "getSessionMusicId":
result.success(getSessionIdMusic());
break;
default:
result.notImplemented();
}
Expand Down
4 changes: 4 additions & 0 deletions lib/logic/playerLogic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class PlayerLogic{
await _platform.invokeMethod("playPausedMusic");
}

Future<int> getAudioSessionID() async{
return await _platform.invokeMethod("getSessionMusicId");
}

void seekToMusic(double seek) async{
await _platform.invokeMethod("seekTo",<String, Object>{
"seek": seek,
Expand Down
101 changes: 37 additions & 64 deletions lib/ux/components/appBars/libraryAppBar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,83 +87,56 @@ class _LibraryAppBarState extends State<LibraryAppBar> with TickerProviderStateM
height: 200,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(0, 0, 0, 10),
margin: EdgeInsets.only(bottom: 2),
child: Text(
"Library",
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontSize: 27,
fontWeight: FontWeight.bold
)
),
),
Column(
mainAxisAlignment: MainAxisAlignment.end,
Row(
children: <Widget>[
Container(
margin: EdgeInsets.fromLTRB(0, 5, 0, 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
boxShadow: [

]
IconButton(
icon: Icon(
Icons.fast_rewind,
color: Colors.white,
),
width: 140,
height: 110,
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
child: Image(
image: AssetImage("lib/assets/images/white-headphone.jpg"),
fit: BoxFit.cover,
),
),
)
onPressed: (){}
),
Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.fast_rewind,
color: Colors.white,
),
onPressed: (){}
),
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,
),
onPressed: (){}
),
],
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,
),
onPressed: (){}
),
],
)
Expand Down
2 changes: 2 additions & 0 deletions lib/ux/components/lists/verticalListSimple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class _VerticalListSimpleState extends State<VerticalListSimple> {
child: ListView.builder(
itemCount: widget.songinfo.length,
scrollDirection: Axis.vertical,
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
itemBuilder: (context, index){
return ListTile(

title: Text(
widget.songinfo.elementAt(index).title,
style: ((){
Expand Down
5 changes: 1 addition & 4 deletions lib/ux/pages/libraryPages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class LibraryPages extends StatefulWidget {
}

class _LibraryPagesState extends State<LibraryPages> {
final List<String> list = ["Zubeen Garg", "Sonu Nigam", "Justin Beiber", "ED Sheeran", "Ariana Grand"];

final List<String> listAlbums = ["Misson China", "Dil Jaale", "Sorry", "Safaar", "Promises"];

@override
Widget build(BuildContext context) {
Expand All @@ -25,7 +22,7 @@ class _LibraryPagesState extends State<LibraryPages> {
builder: (context, snap){
if(snap.data!=null){
List<SongInfo> list = snap.data;
return list.isNotEmpty?VerticalListSimple(list):Center(child: Text("No songs found"),);
return list.isNotEmpty?VerticalListSimple(list):Expanded(child: Center(child: Text("No songs found"),));
}else{
return Expanded(
child: Column(
Expand Down
2 changes: 1 addition & 1 deletion lib/ux/pages/navPages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class _NavPagesState extends State<NavPages> {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
extendBody: false,
//body of the nav bar
body: IndexedStack(
index: _currentIndex,
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
flutter_icons: ^1.1.0
provider: ^3.0.0





Expand Down

0 comments on commit a4759f8

Please sign in to comment.