Currently I am working on Project which is to build a music player. Music player will be similar to current music players out there. My design is like I have a mainActivity and in mainactivity a viewpager with 5 different tab(Songs, Artist, Albums, Generes, PlayList fragments). I started working on Songs Fragment. I have a recyclerview which will populate songs from device. Currently what I did is created a songs class as a record structure, created adapter for recyclerview and created a ArrayList of songs which will hold objects of songs containing song detail , basic design. Should I complete other fragments with same design, so I will be ended with different ArrayList for every fragment. And how should I handle music playback for different fragments. For example if user selected a songs to play from Songs fragment then I want a default "Now playing" queue which will be the default list of songs fragment and it can automatically play next song. Similarly if user selected from artist and then only those artist's song should be in Now playing queue. So to achieve this should I have to maintain different list for individual fragment or is there any better way? It would be great if anyone can help me out. Cheers!
Asked
Active
Viewed 1,378 times
-8
-
SO is not the place to ask for suggestions, it's for specific programming questions. – Denny May 31 '17 at 06:56
-
@Denny yea agree but this is sort of designing question which is related to programming. I am stuck at a point where I don't know what to do, but I did something which I described in the question. And I wanted to know if I did was right or is there any other way out. Isn't this type of questions are allowed? – Rahul Bhavani May 31 '17 at 07:03
-
No, it is for specific programming questions, not for asking suggestions or recommendations. – Denny May 31 '17 at 07:05
-
Sorry, my bad.. – Rahul Bhavani May 31 '17 at 07:09
-
@Denny, Just wandering isn't this question also asking for suggestion? https://stackoverflow.com/questions/16642829/how-to-enqueue-music-to-default-android-music-player-via-app?rq=1 – Rahul Bhavani May 31 '17 at 07:30
-
Yes it is, but it was asked four years ago and times have changed. If it was asked now, it would probably be closed. Same for [this](https://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android-application) question, it shows close to no effort at all and would also be closed if it was asked now. – Denny May 31 '17 at 07:34
-
Ok, is there any place where I can ask this type of questions? – Rahul Bhavani May 31 '17 at 07:38
-
Reddit/xda forums – Denny May 31 '17 at 07:43
1 Answers
0
It's simple...on recyclerview adapter click, pass arraylist of songs and current clicked pos to service class, then from service class play current and as soon finished play next position
Like this :
OnClick {
service.playmusic(adapter. getsonglist(), current clicked pos)
}
and in service class you got arraylist and pos
so do this
List<song> playlist = new ArrayList<>();
playlist = songlist //this is from adpter click
Song song = playlist.get(position) // current position from clicked adapter.
finally set id or path in mediaplayer.set data source (); prepare async or sync and play.
onCompletion check if playlist is finished or not if finished and have data then play next position.
Also, this playlist you can show as queue list in the playingScreen's queueList .
Hope, this will clear your problem :)

user8119020
- 117
- 3
-
Thank you, I am working on the same and learning how to send Arraylist of object to Service and setup a broadcastReceiver for the same. Thanks for your answer, really appreciated :) – Rahul Bhavani Jun 28 '17 at 06:44