Browse Source

fix: music local

tongmengxiao 4 months ago
parent
commit
c2cb1e6c79

+ 1 - 0
baseswago/src/main/java/com/swago/baseswago/agora/AgoraManager.kt

@@ -124,6 +124,7 @@ object AgoraManager {
                     override fun onAudioMixingStateChanged(state: Int, reason: Int) {
                         super.onAudioMixingStateChanged(state, reason)
                         LogUtil.d("onAudioMixingStateChanged" , "结果--$state  $reason")
+                        iSwagoIRtcEngineEventHandler?.onAudioMixingStateChanged(state,reason)
                     }
                 })
             setChannelProfile()

+ 2 - 0
baseswago/src/main/java/com/swago/baseswago/agora/ISwagoIRtcEngineEventHandler.kt

@@ -33,4 +33,6 @@ interface ISwagoIRtcEngineEventHandler {
         imageHeight: Int,
         faces: Array<out IRtcEngineEventHandler.AgoraFacePositionInfo>?
     )
+
+    fun onAudioMixingStateChanged(state:Int, reason:Int)
 }

+ 1 - 1
baseswago/src/main/java/com/swago/baseswago/dialog/ChoiceDialogFragment.kt

@@ -49,7 +49,7 @@ class ChoiceDialogFragment : BaseXDFragment<DialogChoiceBinding>() {
                 binding.tvCancel.text = lefChoiceText
             }
             if (!rightChoiceText.isNullOrEmpty()){
-                binding.tvCancel.text = rightChoiceText
+                binding.tvSure.text = rightChoiceText
             }
 
             binding.tvCancel.setOnClickListener(object:NoDoubleClickListener(){

+ 4 - 0
room/src/main/java/com/swago/room/anchor/AnchorRoomActivity.kt

@@ -521,6 +521,10 @@ class AnchorRoomActivity : AbsAnchorActivity<ActivityAnchorRoomBinding, IRoomInf
         LogUtil.d("onFacePositionChanged${faces?.size}")
     }
 
+    override fun onAudioMixingStateChanged(state: Int, reason: Int) {
+        anchorRoomFragment?.onAudioMixingStateChanged(state,reason)
+    }
+
     /**************************PK******************************/
     private val marginTopValue by lazy {
         ImmersionBar.getStatusBarHeight(this) + DpPxUtil.dip2px(78f)

+ 19 - 0
room/src/main/java/com/swago/room/anchor/AnchorRoomFragment.kt

@@ -24,6 +24,8 @@ import com.swago.room.hongbao.RedEnvelopeDialog
 import com.swago.room.inter.IFooter
 import com.swago.room.inter.IHeader
 import com.swago.room.lianmai.AnchorLianMaiDialog
+import com.swago.room.music.MusicModel
+import com.swago.room.music.MyMusicDialog
 import com.swago.room.pk.PKAcceptDialog
 import com.swago.room.pk.PKInviteDialog
 import com.swago.room.pk.PKSearchLisDialog
@@ -39,6 +41,7 @@ class AnchorRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
     private var footerView : AnchorFooterView? = null
     private var pkAcceptDialog:PKAcceptDialog? = null
     private var pkInviteDialog:PKInviteDialog? = null
+    private var chooseMusic:MusicModel? = null
 
     override fun initOther() {
         super.initOther()
@@ -160,6 +163,14 @@ class AnchorRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
         }
     }
 
+    private fun openMusicDialog() {
+        MyMusicDialog.newInstance(chooseMusic).apply {
+            openChooseMusicFun = {
+                chooseMusic = it
+            }
+        }.show(childFragmentManager,"MyMusicDialog")
+    }
+
     private fun openLianMaiListDialog() {
         AnchorLianMaiDialog.newInstance().show(childFragmentManager,"AnchorLianMaiDialog")
     }
@@ -245,6 +256,14 @@ class AnchorRoomFragment : BaseComFragment<FragmentBaseComBinding>() {
         super.closeRoomed()
     }
 
+    fun onAudioMixingStateChanged(state: Int, reason: Int) {
+        if (state == 710){
+            footerView?.playMusicAnimator(true)
+        } else if (state == 713 || state == 711 || state == 714){
+            footerView?.playMusicAnimator(false)
+        }
+    }
+
     override val iHeader: IHeader by lazy {
         ComHeaderView(requireContext())
     }

+ 0 - 4
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -669,10 +669,6 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
         ShareDialog.newInstance().show(childFragmentManager,"ShareDialog")
     }
 
-    fun openMusicDialog() {
-        MyMusicDialog.newInstance().show(childFragmentManager,"MyMusicDialog")
-    }
-
     private fun initMaiPosition() {
         allPositionXYList.clear()
         val centerX = DpPxUtil.getScreenWidth() / 2

+ 1 - 1
room/src/main/java/com/swago/room/music/LocalMusicActivity.kt

@@ -39,7 +39,7 @@ class LocalMusicActivity : BaseXActivity<ActivityLocalMusicBinding>() {
 
     override fun initOther() {
         setBackView(binding.toolbar.ivBack)
-        binding.toolbar.tvTitle.text = AppContext.getContext().resources.getString(R.string.swago_offical_msg)
+        binding.toolbar.tvTitle.text = "Local Music"
 
         binding.rv.layoutManager = layoutManager
         binding.rv.adapter = adapter

+ 28 - 2
room/src/main/java/com/swago/room/music/MyMusicDialog.kt

@@ -11,6 +11,7 @@ import com.swago.baseswago.agora.AgoraManager
 import com.swago.baseswago.constant.ARouteConstant
 import com.swago.baseswago.dialog.BaseXDFragment
 import com.swago.baseswago.dialog.ChoiceDialogFragment
+import com.swago.baseswago.model.live.pk.PKLiverModel
 import com.swago.baseswago.util.AppContext
 import com.swago.room.R
 import com.swago.room.database.DBHelper
@@ -19,9 +20,13 @@ import com.swago.room.databinding.DialogMyMusicBinding
 class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
     val music_binding get() = binding
     var isLocalCome = false
+    var openChooseMusicFun:((musicModel: MusicModel?)->Unit)? =null
+    var musicModel : MusicModel? = null
+
     private val musicList by lazy {
         ArrayList<MusicModel>()
     }
+
     private val adapter by lazy {
         MyMusicAdapter()
     }
@@ -29,10 +34,10 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
         get() = LinearLayoutManager(activity)
 
     companion object {
-        const val select_local_result = 10002
-        fun newInstance(): MyMusicDialog {
+        fun newInstance(chooseMusic: MusicModel?): MyMusicDialog {
             val args = Bundle()
             val fragment = MyMusicDialog()
+            args.putParcelable("chooseMusic",chooseMusic)
             fragment.arguments = args
             return fragment
         }
@@ -45,6 +50,10 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
     }
 
     override fun initOther() {
+        arguments?.let {
+            musicModel =  it.getParcelable("chooseMusic")
+
+        }
         music_binding.rvMusic.layoutManager = layoutManager
         music_binding.rvMusic.adapter = adapter
         music_binding.ivClose.setOnClickListener {
@@ -57,6 +66,13 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
         if (!data.isNullOrEmpty()){
             music_binding.clAdd.visibility = View.VISIBLE
             music_binding.clNoContent.visibility = View.GONE
+            data.forEachIndexed { index, item ->
+                if (musicModel != null && item.id == musicModel?.id){
+                    data[index].setIsPlaying(true)
+                    return@forEachIndexed
+                }
+
+            }
             musicList.addAll(data)
             adapter.setNewData(musicList)
         } else {
@@ -85,6 +101,7 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
                             DBHelper.getMusicModel()?.delete(adapter.data[position])
                             musicList.remove(adapter.data[position])
                             adapter.setNewData(musicList)
+                            AgoraManager.getRtcEngine()?.stopAudioMixing()
                             if (adapter.data.isEmpty()){
                                 music_binding.clAdd.visibility = View.GONE
                                 music_binding.clNoContent.visibility = View.VISIBLE
@@ -101,6 +118,7 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
                 adapter.data[position].setIsPlaying(false)
                 adapter.notifyItemChanged(position)
                 AgoraManager.getRtcEngine()?.stopAudioMixing()
+                openChooseMusicFun?.invoke(null)
                 return@setOnItemClickListener
             }
             adapter.data.forEachIndexed { index, musicModel ->
@@ -110,6 +128,7 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
                     return@forEachIndexed
                 }
             }
+            openChooseMusicFun?.invoke(adapter.data[position])
             adapter.data[position].setIsPlaying(true)
             AgoraManager.getRtcEngine()?.startAudioMixing(
                 adapter.data[position].data,
@@ -131,6 +150,13 @@ class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
                 binding.clAdd.visibility = View.VISIBLE
                 binding.clNoContent.visibility = View.GONE
                 musicList.clear()
+                data.forEachIndexed { index, item ->
+                    if (musicModel != null && item.id == musicModel?.id){
+                        data[index].setIsPlaying(true)
+                        return@forEachIndexed
+                    }
+
+                }
                 musicList.addAll(data)
                 adapter.setNewData(musicList)
             } else {

+ 4 - 0
room/src/main/java/com/swago/room/user/UserRoomActivity.kt

@@ -429,6 +429,10 @@ class UserRoomActivity : AbsUserActivity<ActivityAbsRoomUserBinding, UserRoomMod
         LogUtil.d("onFacePositionChanged${faces?.size}")
     }
 
+    override fun onAudioMixingStateChanged(state: Int, reason: Int) {
+
+    }
+
     fun gotoTargetRoom(anchorId: String) {
         iRoomInfos.forEachIndexed { index, userRoomModel ->
             if (userRoomModel?.momentModel != null) {

+ 18 - 0
room/src/main/java/com/swago/room/widget/AnchorFooterView.kt

@@ -1,5 +1,7 @@
 package com.swago.room.widget
 
+import android.animation.ObjectAnimator
+import android.animation.ValueAnimator
 import android.content.Context
 import android.util.AttributeSet
 import android.view.LayoutInflater
@@ -39,6 +41,7 @@ class AnchorFooterView : ConstraintLayout, IFooter, IRoomActiveListener {
     var openGiftPanelFun:(()->Unit)? = null
     var openLocalMusicFun:(()->Unit)? = null
     var isMute = false
+    private lateinit var rotationAnimator: ObjectAnimator
 
     constructor(context: Context) : this(context, null)
     constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
@@ -55,6 +58,12 @@ class AnchorFooterView : ConstraintLayout, IFooter, IRoomActiveListener {
         SwagoRoomManager.addListener(this)
         binding = LayoutAnchorFooterViewBinding.inflate(LayoutInflater.from(context), this, true)
 
+        rotationAnimator = ObjectAnimator.ofFloat(binding.ivAudioMusic, "rotation", 0f, 360f).apply {
+            duration = 1500
+            repeatCount = ValueAnimator.INFINITE
+            repeatMode = ValueAnimator.RESTART
+            interpolator = null // 使用线性插值器
+        }
         UserInfo.getUserInfo()?.let {
             if (it.user_type == 1&&it.user_agent_id>0){
                 binding.ivPK.visibility = View.VISIBLE
@@ -188,5 +197,14 @@ class AnchorFooterView : ConstraintLayout, IFooter, IRoomActiveListener {
         binding.ivDot.visibility = View.VISIBLE
     }
 
+    fun playMusicAnimator(isPlaying:Boolean){
+        binding.ivAudioMusic.post{
+            if (isPlaying){
+                rotationAnimator.start()
+            } else {
+                rotationAnimator.cancel()
+            }
+        }
+    }
 
 }

+ 3 - 3
room/src/main/res/layout/item_my_music.xml

@@ -12,7 +12,7 @@
         android:layout_height="wrap_content"
         android:paddingStart="16dp"
         android:src="@mipmap/ic_music_stop"
-        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintBottom_toBottomOf="parent"/>
 
@@ -20,7 +20,7 @@
         android:id="@+id/tvName"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        app:layout_constraintLeft_toRightOf="@+id/ivPlay"
+        app:layout_constraintStart_toEndOf="@+id/ivPlay"
         app:layout_constraintTop_toTopOf="parent"
         android:layout_marginTop="16dp"
         android:layout_marginEnd="@dimen/dp_40"
@@ -51,7 +51,7 @@
         android:id="@+id/tvDuration"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        app:layout_constraintLeft_toRightOf="@+id/ivPlay"
+        app:layout_constraintStart_toEndOf="@+id/ivPlay"
         app:layout_constraintTop_toBottomOf="@+id/tvName"
         android:layout_marginStart="@dimen/dp_10"
         android:layout_marginTop="@dimen/dp_4"

+ 2 - 4
tuikit/src/main/java/com/tencent/qcloud/tim/uikit/modules/chat/layout/message/holder/MessageContentHolder.java

@@ -160,18 +160,16 @@ public abstract class MessageContentHolder extends MessageEmptyHolder {
                 rightSvgaImage.setVisibility(View.VISIBLE);
                 rightSvgaImage.setImageDrawable(drawable);
                 rightSvgaImage.startAnimation();
-            }else {
-                rightSvgaImage.setVisibility(View.INVISIBLE);
             }
+            leftSvgaImage.setVisibility(View.INVISIBLE);
         } else {
             if (properties.getLeftSvgaAvatar() != null){
                 SVGADrawable drawable = new SVGADrawable(properties.getLeftSvgaAvatar());
                 leftSvgaImage.setVisibility(View.VISIBLE);
                 leftSvgaImage.setImageDrawable(drawable);
                 leftSvgaImage.startAnimation();
-            } else {
-                leftSvgaImage.setVisibility(View.INVISIBLE);
             }
+            rightSvgaImage.setVisibility(View.INVISIBLE);
         }
 
         //// 聊天气泡的点击事件处理