[6.3.0]
[music] [seek实现]
This commit is contained in:
@@ -6,6 +6,7 @@ import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Message
|
||||
import android.text.TextUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
|
||||
//播放试听
|
||||
object Audition: MediaPlayer.OnPreparedListener,
|
||||
@@ -117,14 +118,8 @@ object Audition: MediaPlayer.OnPreparedListener,
|
||||
return false
|
||||
}
|
||||
|
||||
fun playOrStop(path: String): Boolean {
|
||||
return if (!TextUtils.equals(oldPath, path)) {
|
||||
play(path)
|
||||
true
|
||||
} else {
|
||||
stop()
|
||||
false
|
||||
}
|
||||
fun seekTo(progress: Int){
|
||||
mediaPlayer?.seekTo(progress)
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
@@ -141,10 +136,11 @@ object Audition: MediaPlayer.OnPreparedListener,
|
||||
}
|
||||
|
||||
override fun onCompletion(mp: MediaPlayer) {
|
||||
if (listener != null) {
|
||||
listener!!.onAuditionCompletion(oldPath)
|
||||
}
|
||||
val tempPath = oldPath
|
||||
oldPath = null
|
||||
if (listener != null) {
|
||||
listener!!.onAuditionCompletion(tempPath)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSeekComplete(mp: MediaPlayer) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mogo.och.common.module.manager.auditionmanager
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.och.common.module.manager.distancemamager.IDistanceListener
|
||||
import com.mogo.och.common.module.manager.distancemamager.TrajectoryAndDistanceManager
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
@@ -10,6 +11,8 @@ object AuditionManager: AuditionCacheManager.DataChangeListener, Audition.OnAudi
|
||||
|
||||
private val dataChangeListeners: ConcurrentHashMap<String, MusicDataChangeListener> = ConcurrentHashMap()
|
||||
|
||||
private const val TAG = "AuditionManager"
|
||||
|
||||
init {
|
||||
AuditionCacheManager.addDataChangeListener(this)
|
||||
Audition.registerOnAuditionListener(this)
|
||||
@@ -89,6 +92,7 @@ object AuditionManager: AuditionCacheManager.DataChangeListener, Audition.OnAudi
|
||||
*/
|
||||
override fun onAuditionCompletion(path:String?) {
|
||||
val oldData = resetData()
|
||||
CallerLogger.d(TAG,"播放完成:${oldData?.songName}--${path}")
|
||||
if(oldData!=null&&oldData.path==path){
|
||||
dataChangeListeners.forEach {
|
||||
it.value.onMusicCompletion(oldData)
|
||||
@@ -153,4 +157,8 @@ object AuditionManager: AuditionCacheManager.DataChangeListener, Audition.OnAudi
|
||||
}
|
||||
}
|
||||
|
||||
fun seekTo(progress: Int) {
|
||||
Audition.seekTo(progress)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,5 +49,10 @@ class MusicListViewModel : ViewModel(), IOCHTaxiPassengerOrderStatusCallback,
|
||||
}, UiThreadHandler.MODE.QUEUE)
|
||||
}
|
||||
|
||||
|
||||
override fun onMusicCompletion(musicData: MusicData) {
|
||||
super.onMusicCompletion(musicData)
|
||||
UiThreadHandler.post({
|
||||
viewCallback?.updateMusicData(musicData, musicData)
|
||||
}, UiThreadHandler.MODE.QUEUE)
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,8 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
|
||||
|
||||
private var animator:ObjectAnimator?=null
|
||||
|
||||
private var isSeekBarTouch = false
|
||||
|
||||
private fun initView() {
|
||||
LayoutInflater.from(context).inflate(R.layout.taxi_p_music_playing, this, true)
|
||||
|
||||
@@ -61,16 +63,24 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
|
||||
viewModel?.showNextMusic()
|
||||
}
|
||||
sb_musuc_progess.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener{
|
||||
var seekToProgress = 0
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
CallerLogger.d(TAG,"progress:${progress}----fromUser:${fromUser}")
|
||||
if(isSeekBarTouch) {
|
||||
CallerLogger.d(TAG, "progress:${progress}----fromUser:${fromUser}")
|
||||
seekToProgress = progress
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {
|
||||
|
||||
isSeekBarTouch = true
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {
|
||||
|
||||
isSeekBarTouch = false
|
||||
viewModel?.seekTo(seekToProgress)
|
||||
seekToProgress = 0
|
||||
}
|
||||
|
||||
})
|
||||
@@ -127,11 +137,9 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
|
||||
}
|
||||
|
||||
private fun startAnimal(){
|
||||
animator?.let {
|
||||
if (!it.isRunning) {
|
||||
animator?.start()
|
||||
return
|
||||
}
|
||||
if(animator!=null){
|
||||
animator?.cancel()
|
||||
animator = null
|
||||
}
|
||||
animator = ObjectAnimator.ofFloat(iv_music_cover, "rotation", 0f, 360f)
|
||||
iv_music_cover.pivotX = (iv_music_cover.getWidth() / 2).toFloat()
|
||||
@@ -144,7 +152,8 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
|
||||
}
|
||||
private fun endAnimal(){
|
||||
if(animator!=null){
|
||||
animator?.pause()
|
||||
animator?.cancel()
|
||||
animator = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,12 +168,17 @@ class MusicPlayingView : ConstraintLayout, MusicPlayingViewModel.IMusicPlayingVi
|
||||
}
|
||||
|
||||
override fun setProgress(currentPlay: Long, duration: Long) {
|
||||
sb_musuc_progess.max = duration.toInt()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
sb_musuc_progess.setProgress(currentPlay.toInt(),true)
|
||||
if(isSeekBarTouch){
|
||||
|
||||
}else{
|
||||
sb_musuc_progess.progress=currentPlay.toInt()
|
||||
sb_musuc_progess.max = duration.toInt()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
sb_musuc_progess.setProgress(currentPlay.toInt(),true)
|
||||
}else{
|
||||
sb_musuc_progess.progress=currentPlay.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
tv_playing_time.text = TimeTransformUtils.stringForTime(currentPlay.toInt())
|
||||
tv_playing_during.text = TimeTransformUtils.stringForTime(duration.toInt())
|
||||
}
|
||||
|
||||
@@ -102,4 +102,8 @@ class MusicPlayingViewModel : ViewModel(), AuditionManager.MusicDataChangeListen
|
||||
showNextMusic()
|
||||
toggle()
|
||||
}
|
||||
|
||||
fun seekTo(progress: Int) {
|
||||
AuditionManager.seekTo(progress)
|
||||
}
|
||||
}
|
||||
BIN
OCH/taxi/passenger/src/main/res/drawable-nodpi/taxt_p_music_bg_relax_bottom.png
Normal file → Executable file
BIN
OCH/taxi/passenger/src/main/res/drawable-nodpi/taxt_p_music_bg_relax_bottom.png
Normal file → Executable file
Binary file not shown.
|
Before Width: | Height: | Size: 235 KiB After Width: | Height: | Size: 50 KiB |
BIN
OCH/taxi/passenger/src/main/res/drawable-nodpi/taxt_p_music_bg_relax_head.png
Normal file → Executable file
BIN
OCH/taxi/passenger/src/main/res/drawable-nodpi/taxt_p_music_bg_relax_head.png
Normal file → Executable file
Binary file not shown.
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 18 KiB |
@@ -171,6 +171,7 @@
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:clickable="true"
|
||||
android:layout_width="@dimen/dp_746"
|
||||
android:layout_height="@dimen/dp_916"/>
|
||||
|
||||
|
||||
@@ -72,15 +72,17 @@
|
||||
android:progress="50"
|
||||
android:paddingStart="@dimen/dp_0"
|
||||
android:paddingEnd="@dimen/dp_0"
|
||||
android:thumb="@null"
|
||||
android:id="@+id/sb_musuc_progess"
|
||||
android:thumb="@null"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tv_author"
|
||||
android:layout_marginTop="@dimen/dp_31"
|
||||
android:progressDrawable="@drawable/taxt_p_music_seekbar_style"
|
||||
android:paddingTop="3dp"
|
||||
android:paddingBottom="@dimen/dp_3"
|
||||
android:layout_width="@dimen/dp_340"
|
||||
android:layout_height="@dimen/dp_4"/>
|
||||
android:layout_height="@dimen/dp_10"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_playing_time"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<color name="taxi_p_576887">#576887</color>
|
||||
<color name="taxi_p_995D6A8C">#995D6A8C</color>
|
||||
<color name="taxi_p_B37E90BF">#B37E90BF</color>
|
||||
<color name="taxi_p_488ED0">#488ED0</color>
|
||||
<color name="taxi_p_488ED0">#44488ED0</color>
|
||||
<color name="taxi_p_598CFF">#598CFF</color>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user