Working on playing a song from the song list

This commit is contained in:
amazing-username
2019-03-24 20:39:44 -04:00
parent 2f40523cfd
commit f99c4b797f
5 changed files with 21 additions and 20 deletions
@@ -10,13 +10,14 @@ import java.lang.Exception
import kotlinx.android.synthetic.main.activity_song_view.*
import kotlinx.android.synthetic.main.content_song_view.*
import com.example.mear.activities.BaseServiceActivity
import com.example.mear.adapters.RecyclerAdapter
import com.example.mear.models.TrackItems
import com.example.mear.R
import com.example.mear.repositories.TrackRepository
import com.example.mear.util.ExtractCover
class SongViewActivity : AppCompatActivity() {
class SongViewActivity : BaseServiceActivity() {
private var trackListItems = arrayListOf<TrackItems>()
private lateinit var adapter: RecyclerAdapter
private lateinit var linearLayoutManager: LinearLayoutManager
@@ -31,6 +32,7 @@ class SongViewActivity : AppCompatActivity() {
try {
window.statusBarColor = resources.getColor(R.color.track_seek)
doBindService()
initializeAdapter()
}
catch (ex: Exception) {
@@ -57,9 +59,10 @@ class SongViewActivity : AppCompatActivity() {
trackListItems = retrieveTrackItems()
adapter = RecyclerAdapter(trackListItems)
adapter.musicService = musicService
trackList.adapter = adapter
trackList.setHasFixedSize(true)
//trackList.setItemViewCacheSize(20);
trackList.setItemViewCacheSize(20);
//trackList.setDrawingCacheEnabled(true);
//trackList.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
}
@@ -102,8 +105,9 @@ class SongViewActivity : AppCompatActivity() {
}
*/
for (track in tracks) {
val cover = ExtractCover(track.songPath)
//val cover = ExtractCover(track.songPath)
var trackCover = ByteArray(0)
/**
if (cover.hasCover() && !done) {
if (index < max ) {
trackCover = cover.retrieveCover()
@@ -116,7 +120,7 @@ class SongViewActivity : AppCompatActivity() {
if (done) {
return trackItems
}
*/
val trackItem = TrackItems(track.id, track.title, track.artist, trackCover!!)
trackItems.add(trackItem)
}
@@ -15,9 +15,12 @@ import com.example.mear.constants.Filenames
import com.example.mear.inflate
import com.example.mear.models.TrackItems
import com.example.mear.R
import com.example.mear.playback.service.MusicService
import com.example.mear.repositories.TrackRepository
class RecyclerAdapter( private val trackItemsSourceInit: ArrayList<TrackItems>) :
RecyclerView.Adapter<RecyclerAdapter.TrackItemsHolder>() {
var musicService: MusicService? = null
override fun getItemCount(): Int {
return trackItemsSourceInit!!.size
@@ -30,12 +33,13 @@ class RecyclerAdapter( private val trackItemsSourceInit: ArrayList<TrackItems>)
override fun onCreateViewHolder(parent: ViewGroup, position: Int): TrackItemsHolder {
val inflatedView = parent.inflate(R.layout.fragment_song_view, false)
return TrackItemsHolder(inflatedView)
return TrackItemsHolder(inflatedView, musicService!!)
}
class TrackItemsHolder(v: View) : RecyclerView.ViewHolder(v), View.OnClickListener {
class TrackItemsHolder(v: View, musicService: MusicService) : RecyclerView.ViewHolder(v), View.OnClickListener {
private var view: View = v
private var musicService: MusicService = musicService
private var trackItem: TrackItems? = null
private val imgWidth = 90
private val imgHeight = 90
@@ -50,6 +54,8 @@ class RecyclerAdapter( private val trackItemsSourceInit: ArrayList<TrackItems>)
val context = itemView.context
val showPhotoIntent = Intent(context, SongViewActivity::class.java)
//showPhotoIntent.putExtra(PHOTO_KEY, trackItem)
val id = trackItem!!.id
musicService.playTrack(id)
context.startActivity(showPhotoIntent)
}
catch (ex: Exception) {
@@ -65,6 +65,9 @@ class MusicService: Service() {
return super.onUnbind(intent)
}
fun playTrack(id: Int) {
}
fun goToPosition(progress: Int) {
trackPlayer!!.seekTo(progress)