2025-10-24 17:55:15 +08:00
|
|
|
|
package com.xscm.moduleutil.widget;
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
|
|
|
|
|
|
import com.xscm.moduleutil.bean.GiftBean;
|
2025-11-24 18:48:14 +08:00
|
|
|
|
import com.xscm.moduleutil.utils.roomview.RoomCPView;
|
2025-10-24 17:55:15 +08:00
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
import java.util.concurrent.LinkedBlockingQueue;
|
|
|
|
|
|
import java.util.concurrent.ThreadPoolExecutor;
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
public class QXGiftPlayerManager {
|
|
|
|
|
|
private static QXGiftPlayerManager instance;
|
|
|
|
|
|
private View bgEffectView;
|
|
|
|
|
|
|
|
|
|
|
|
private GiftAnimView fullEffectView;
|
|
|
|
|
|
private GiftAnimView chatEffectView;
|
2025-11-24 18:48:14 +08:00
|
|
|
|
|
|
|
|
|
|
private RoomCPView roomCPView;
|
2025-10-24 17:55:15 +08:00
|
|
|
|
private Context context;
|
|
|
|
|
|
|
|
|
|
|
|
private QXGiftPlayerManager(Context context) {
|
|
|
|
|
|
this.context = context.getApplicationContext();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static synchronized QXGiftPlayerManager getInstance(Context context) {
|
|
|
|
|
|
if (instance == null) {
|
|
|
|
|
|
instance = new QXGiftPlayerManager(context);
|
|
|
|
|
|
}
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
}
|
|
|
|
|
|
public View getDefaultBgEffectView() {
|
|
|
|
|
|
if (bgEffectView == null) {
|
|
|
|
|
|
initBgEffectView();
|
|
|
|
|
|
}
|
|
|
|
|
|
return bgEffectView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 18:48:14 +08:00
|
|
|
|
public RoomCPView getRoomCPView(){
|
|
|
|
|
|
if (roomCPView==null){
|
|
|
|
|
|
initRoomCPView();
|
|
|
|
|
|
}
|
|
|
|
|
|
return roomCPView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-10-24 17:55:15 +08:00
|
|
|
|
public GiftAnimView getDefaultFullEffectView() {
|
|
|
|
|
|
if (fullEffectView == null) {
|
|
|
|
|
|
initFullEffectView();
|
|
|
|
|
|
}
|
|
|
|
|
|
return fullEffectView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public GiftAnimView getDefaultChatEffectView() {
|
|
|
|
|
|
if (chatEffectView == null) {
|
|
|
|
|
|
initChatEffectView();
|
|
|
|
|
|
}
|
|
|
|
|
|
return chatEffectView;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initBgEffectView() {
|
|
|
|
|
|
bgEffectView = new FrameLayout(context);
|
|
|
|
|
|
bgEffectView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
|
|
));
|
|
|
|
|
|
bgEffectView.setBackgroundColor(0x00000000);
|
|
|
|
|
|
bgEffectView.setClickable(false); // userInteractionEnabled = NO
|
|
|
|
|
|
|
2025-11-24 18:48:14 +08:00
|
|
|
|
// 添加全屏特效视图、聊天特效视图和CP视图
|
2025-10-24 17:55:15 +08:00
|
|
|
|
((ViewGroup) bgEffectView).addView(getDefaultFullEffectView());
|
|
|
|
|
|
((ViewGroup) bgEffectView).addView(getDefaultChatEffectView());
|
2025-11-24 18:48:14 +08:00
|
|
|
|
((ViewGroup) bgEffectView).addView(getRoomCPView());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initRoomCPView() {
|
|
|
|
|
|
roomCPView=new RoomCPView(context);
|
|
|
|
|
|
roomCPView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT
|
2025-12-08 19:00:15 +08:00
|
|
|
|
));
|
2025-11-24 18:48:14 +08:00
|
|
|
|
// 创建专用线程池替代GCD队列
|
|
|
|
|
|
ExecutorService queue = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
|
|
|
|
|
|
new LinkedBlockingQueue<Runnable>(),
|
|
|
|
|
|
Executors.defaultThreadFactory());
|
|
|
|
|
|
roomCPView.setQueue(queue);
|
2025-10-24 17:55:15 +08:00
|
|
|
|
}
|
2025-11-24 18:48:14 +08:00
|
|
|
|
|
2025-10-24 17:55:15 +08:00
|
|
|
|
public void displayFullEffectView(String gift) {
|
|
|
|
|
|
getDefaultFullEffectView().displayEffectView(gift);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void displayFullEffectView1(List<String> stringList){
|
|
|
|
|
|
getDefaultFullEffectView().displayEffectView1(stringList);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void displayChatEffectView(String gift) {
|
|
|
|
|
|
getDefaultChatEffectView().displayEffectView(gift);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 18:48:14 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 显示CP动画
|
|
|
|
|
|
* @param room_head1 头像1的URL
|
|
|
|
|
|
* @param room_head2 头像2的URL
|
|
|
|
|
|
* @param room_cp_name1 名称1
|
|
|
|
|
|
* @param room_cp_name2 名称2
|
|
|
|
|
|
* @param mp4Path MP4动画文件路径
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void displayCPView(String room_head1, String room_head2, String room_cp_name1, String room_cp_name2, String mp4Path) {
|
|
|
|
|
|
getRoomCPView().displayEffectView(room_head1, room_head2, room_cp_name1, room_cp_name2, mp4Path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 开启或关闭CP动画
|
|
|
|
|
|
* @param isShow 是否显示
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void openOrCloseCPViewWith(boolean isShow) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 停止CP动画
|
|
|
|
|
|
*/
|
|
|
|
|
|
public void stopCPPlay() {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-24 17:55:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void openOrCloseEffectViewWith(boolean isShow) {
|
|
|
|
|
|
getDefaultFullEffectView().openOrCloseEffectViewWith(isShow);
|
|
|
|
|
|
getDefaultChatEffectView().openOrCloseEffectViewWith(isShow);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void destroyEffectSvga() {
|
|
|
|
|
|
if (fullEffectView != null) {
|
|
|
|
|
|
fullEffectView.destroyEffectView();
|
|
|
|
|
|
if (bgEffectView != null) {
|
|
|
|
|
|
((ViewGroup) bgEffectView).removeView(fullEffectView);
|
|
|
|
|
|
}
|
|
|
|
|
|
fullEffectView = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (chatEffectView != null) {
|
|
|
|
|
|
chatEffectView.destroyEffectView();
|
|
|
|
|
|
if (bgEffectView != null) {
|
|
|
|
|
|
((ViewGroup) bgEffectView).removeView(chatEffectView);
|
|
|
|
|
|
}
|
|
|
|
|
|
chatEffectView = null;
|
|
|
|
|
|
}
|
2025-12-08 19:00:15 +08:00
|
|
|
|
|
2025-11-24 18:48:14 +08:00
|
|
|
|
if (roomCPView != null) {
|
|
|
|
|
|
// 先调用destroyEffectView方法,它会自动从父视图中移除
|
|
|
|
|
|
roomCPView.destroyEffectView();
|
2025-12-08 19:00:15 +08:00
|
|
|
|
if (bgEffectView != null) {
|
|
|
|
|
|
((ViewGroup) bgEffectView).removeView(roomCPView);
|
|
|
|
|
|
}
|
2025-11-24 18:48:14 +08:00
|
|
|
|
roomCPView = null;
|
|
|
|
|
|
}
|
2025-10-24 17:55:15 +08:00
|
|
|
|
|
|
|
|
|
|
if (bgEffectView != null) {
|
|
|
|
|
|
bgEffectView = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void stopPlay() {
|
|
|
|
|
|
if (fullEffectView != null) {
|
|
|
|
|
|
fullEffectView.stopPlay();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (chatEffectView != null) {
|
|
|
|
|
|
chatEffectView.stopPlay();
|
|
|
|
|
|
}
|
2025-11-24 18:48:14 +08:00
|
|
|
|
if (roomCPView != null) {
|
|
|
|
|
|
}
|
2025-10-24 17:55:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initFullEffectView() {
|
|
|
|
|
|
fullEffectView = new GiftAnimView(context);
|
|
|
|
|
|
fullEffectView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
|
|
));
|
|
|
|
|
|
// 创建专用线程池替代GCD队列
|
|
|
|
|
|
ExecutorService queue = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
|
|
|
|
|
|
new LinkedBlockingQueue<Runnable>(),
|
|
|
|
|
|
Executors.defaultThreadFactory());
|
|
|
|
|
|
fullEffectView.setQueue(queue);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initChatEffectView() {
|
|
|
|
|
|
chatEffectView = new GiftAnimView(context);
|
|
|
|
|
|
chatEffectView.setLayoutParams(new ViewGroup.LayoutParams(
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
|
|
|
));
|
|
|
|
|
|
// 创建专用线程池替代GCD队列
|
|
|
|
|
|
ExecutorService queue = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
|
|
|
|
|
|
new LinkedBlockingQueue<Runnable>(),
|
|
|
|
|
|
Executors.defaultThreadFactory());
|
|
|
|
|
|
chatEffectView.setQueue(queue);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|