play the clicked song on the queue
This commit is contained in:
parent
220d552b02
commit
fa1e09916d
5 changed files with 34 additions and 14 deletions
|
@ -138,7 +138,7 @@
|
|||
<action android:name="com.simplemobiletools.musicplayer.action.NEXT"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.RESET"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.EDIT"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.PLAYPOS"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.PLAY_TRACK"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.REFRESH_LIST"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.SET_PROGRESS"/>
|
||||
<action android:name="com.simplemobiletools.musicplayer.action.SKIP_BACKWARD"/>
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
package com.simplemobiletools.musicplayer.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import com.google.gson.Gson
|
||||
import com.simplemobiletools.commons.helpers.mydebug
|
||||
import com.simplemobiletools.musicplayer.R
|
||||
import com.simplemobiletools.musicplayer.adapters.QueueAdapter
|
||||
import com.simplemobiletools.musicplayer.adapters.SongsAdapter
|
||||
import com.simplemobiletools.musicplayer.helpers.*
|
||||
import com.simplemobiletools.musicplayer.helpers.TRACK_POS
|
||||
import com.simplemobiletools.musicplayer.models.Events
|
||||
import com.simplemobiletools.musicplayer.models.Track
|
||||
import com.simplemobiletools.musicplayer.services.MusicService
|
||||
import kotlinx.android.synthetic.main.activity_queue.*
|
||||
import kotlinx.android.synthetic.main.activity_songs.*
|
||||
|
@ -21,12 +27,7 @@ class QueueActivity : SimpleActivity() {
|
|||
setContentView(R.layout.activity_queue)
|
||||
bus = EventBus.getDefault()
|
||||
bus!!.register(this)
|
||||
|
||||
QueueAdapter(this, MusicService.mTracks, queue_list) {
|
||||
|
||||
}.apply {
|
||||
queue_list.adapter = this
|
||||
}
|
||||
setupAdapter()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -39,8 +40,25 @@ class QueueActivity : SimpleActivity() {
|
|||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun queueUpdated(event: Events.QueueUpdated) {
|
||||
private fun setupAdapter() {
|
||||
val adapter = queue_list.adapter
|
||||
if (adapter == null) {
|
||||
QueueAdapter(this, MusicService.mTracks, queue_list) {
|
||||
Intent(this, MusicService::class.java).apply {
|
||||
action = PLAY_TRACK
|
||||
putExtra(TRACK_ID, (it as Track).id)
|
||||
startService(this)
|
||||
}
|
||||
}.apply {
|
||||
queue_list.adapter = this
|
||||
}
|
||||
} else {
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
fun trackChangedEvent(event: Events.TrackChanged) {
|
||||
setupAdapter()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,7 +206,7 @@ class SongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
|
|||
setupIconDescriptions()
|
||||
Intent(activity, MusicService::class.java).apply {
|
||||
putExtra(TRACK_POS, pos)
|
||||
action = PLAYPOS
|
||||
//action = PLAYPOS
|
||||
activity.startService(this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ const val PLAYPAUSE = PATH + "PLAYPAUSE"
|
|||
const val NEXT = PATH + "NEXT"
|
||||
const val RESET = PATH + "RESET"
|
||||
const val EDIT = PATH + "EDIT"
|
||||
const val PLAYPOS = PATH + "PLAYPOS"
|
||||
const val PLAY_TRACK = PATH + "PLAY_TRACK"
|
||||
const val REFRESH_LIST = PATH + "REFRESH_LIST"
|
||||
const val SET_PROGRESS = PATH + "SET_PROGRESS"
|
||||
const val SET_EQUALIZER = PATH + "SET_EQUALIZER"
|
||||
|
|
|
@ -144,7 +144,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
PLAYPAUSE -> handlePlayPause()
|
||||
NEXT -> handleNext()
|
||||
RESET -> handleReset()
|
||||
PLAYPOS -> playTrack(intent)
|
||||
PLAY_TRACK -> playTrack(intent)
|
||||
EDIT -> handleEdit(intent)
|
||||
FINISH -> handleFinish()
|
||||
FINISH_IF_NOT_PLAYING -> finishIfNotPlaying()
|
||||
|
@ -656,9 +656,11 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
|
|||
setupTrack()
|
||||
} else {
|
||||
mPlayOnPrepare = true
|
||||
/*val pos = intent.getIntExtra(SONG_POS, 0)
|
||||
setTrack(pos, true)*/
|
||||
val trackId = intent.getLongExtra(TRACK_ID, 0L)
|
||||
setTrack(trackId, false)
|
||||
broadcastTrackChange(mCurrTrack)
|
||||
}
|
||||
|
||||
mMediaSession?.isActive = true
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue