交友房

This commit is contained in:
2025-10-31 15:18:32 +08:00
parent 6098927e73
commit 7a81001f2a
21 changed files with 1148 additions and 2611 deletions

View File

@@ -1,7 +1,9 @@
package com.xscm.moduleutil;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = false)
@Data
public class BaseEvent {
}

View File

@@ -3,9 +3,11 @@ package com.xscm.moduleutil.event;
import com.xscm.moduleutil.BaseEvent;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
@EqualsAndHashCode(callSuper = true)
@Data
public class RedBean extends BaseEvent implements Serializable {
private static final long serialVersionUID = 1L;

View File

@@ -3,7 +3,9 @@ package com.xscm.moduleutil.event;
import com.xscm.moduleutil.BaseEvent;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class RoomOwnerLeaveEvent extends BaseEvent {
private String room_id;

View File

@@ -4,8 +4,10 @@ import com.xscm.moduleutil.BaseEvent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@EqualsAndHashCode(callSuper = true)
@Data
@AllArgsConstructor
@NoArgsConstructor

View File

@@ -12,7 +12,7 @@ import lombok.Data;
* @Description 判断是否是电影房$
*/
@Data
public class SurfaceEvent extends BaseEvent {
public class SurfaceEvent extends BaseEvent {
private SurfaceView surfaceView;
private int type;

View File

@@ -362,46 +362,6 @@ public class AgoraManager {
// 填入用于鉴权的 Token
contentCenterConfiguration.token = SpUtil.getRtmToken();
// 创建 IAgoraMusicContentCenterEventHandler用于 SDK 向客户端发送音乐内容中心事件通知
// contentCenterConfiguration.eventHandler = new IMusicContentCenterEventHandler() {
// @Override
// public void onPreLoadEvent(String requestId, long songCode, int percent, String lyricUrl, int status, int errorCode) {
// LogUtils.e("@@@1", "requestId: " + requestId + ", songCode: " + songCode + ", percent: " + percent + ", lyricUrl: " + lyricUrl + ", status: " + status + ", errorCode: " + errorCode);
// if (!lyricUrl.isEmpty() && percent == 100 && !isBjMusic) {
// getLyricsInstance(lyricUrl);
// }
//// musicPlayer.open(songCode, 0);
// }
//
// @Override
// public void onMusicCollectionResult(String requestId, int page, int pageSize, int total, Music[] list, int errorCode) {
// LogUtils.e("@@@2", "requestId: " + requestId + ", page: " + page + ", pageSize: " + pageSize + ", total: " + total);
// MusicBean musicBean = new MusicBean();
// musicBean.setMusicList(Arrays.asList(list));
// musicBean.setPage(page);
// EventBus.getDefault().post(musicBean);
// }
//
// @Override
// public void onMusicChartsResult(String requestId, MusicChartInfo[] list, int errorCode) {
// LogUtils.e("@@@", "requestId: " + requestId);
// }
//
// @Override
// public void onLyricResult(String requestId, long songCode, String lyricUrl, int errorCode) {
// LogUtils.e("@@@22", "requestId: " + requestId + ", songCode: " + songCode + ", lyricUrl: " + lyricUrl + ", errorCode: " + errorCode);
// if (lyricUrl != null && !isBjMusic) {
// getLyricsInstance(lyricUrl);
// }
// }
//
// @Override
// public void onSongSimpleInfoResult(String requestId, long songCode, String simpleInfo, int errorCode) {
// LogUtils.e("@@@", "requestId: " + requestId + ", songCode: " + songCode + ", simpleInfo: " + simpleInfo + ", errorCode: " + errorCode);
// }
// };
// 初始化 IAgoraMusicContentCenter
musicContentCenter.initialize(contentCenterConfiguration);
if (musicPlayer != null) {
musicPlayer = null;
@@ -413,15 +373,8 @@ public class AgoraManager {
if (state == 0) {
musicPlayer.stop();
musicPlayer.open(songCode, 0);
// getLyricsInstance(lyricUrl);
}
LogUtils.e("AgoraManager", "isPreload2: " + songCode, "percent: " + percent);
// if (!lyricUrl.isEmpty() && percent == 100 && !isBjMusic) {
// musicPlayer.stop();
// musicPlayer.open(songCode, 0);
//// getLyricsInstance(lyricUrl);
// }
}
@Override
@@ -473,19 +426,12 @@ public class AgoraManager {
@Override
public void onUserJoined(int uid, int elapsed) {//远端用户加入频道
// for (IRtcEngineEventHandler handler : eventHandlers) {
// if (handler != null) {
// handler.onUserJoined(uid, elapsed);
//
// }
// }
for (SoundLevelUpdateListener listener : soundLevelUpdateListeners) {
if (listener != null) {
ThreadUtils.runOnUiThread(() -> {
// 远程用户音量变化
listener.userJoined(uid, elapsed);
// }
});
}
}
@@ -500,19 +446,13 @@ public class AgoraManager {
@Override
public void onUserOffline(int uid, int reason) {//远端用户离开频道
// for (IRtcEngineEventHandler handler : eventHandlers) {
// if (handler != null) {
// handler.onUserOffline(uid, reason);
// }
for (SoundLevelUpdateListener listener : soundLevelUpdateListeners) {
if (listener != null) {
ThreadUtils.runOnUiThread(() -> {
// 远程用户音量变化
listener.userOffline(uid, reason);
// }
});
}
// }
}
SurfaceView renderView = null;
rtcEngine.setupRemoteVideo(new VideoCanvas(null, Constants.RENDER_MODE_FIT, uid));
@@ -535,7 +475,6 @@ public class AgoraManager {
ThreadUtils.runOnUiThread(() -> {
// 远程用户音量变化
listener.onRemoteSoundLevelUpdate(uid > 0 ? String.valueOf(uid) : SpUtil.getUserId() + "", volume);
// }
});
}
}
@@ -705,39 +644,8 @@ public class AgoraManager {
}
}
public void joinChannelEx(String token, String channelId, int uid,String pkUserIds) {
if (rtcEngine == null) {
init(CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId());
}
if (rtcEngine != null) {
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
options.channelProfile = Constants.CHANNEL_PROFILE_LIVE_BROADCASTING;
options.publishMicrophoneTrack = true; // 是否发布麦克风音频
options.enableAudioRecordingOrPlayout = true;
options.autoSubscribeAudio = true;
connection = new RtcConnection();
connection.channelId = channelId;
connection.localUid = SpUtil.getUserId();
pkRoomId = channelId;
pkUserId = Integer.parseInt(pkUserIds);
// rtcEngine.joinChannelEx(token, connection, options, getDefaultEventHandler());
// muteAllRemoteAudioStreamsEx(true);
// muteAllRemoteAudioStreamsExUserId(false);
}
}
public void leaveChannelEx(String mRoomId, int uid) {
if (rtcEngine != null) {
RtcConnection connection = new RtcConnection();
connection.channelId = mRoomId;
connection.localUid = uid;
// rtcEngine.leaveChannelEx(connection);
}
}
public void updateChannelMediaOptions() {
if (rtcEngine != null) {
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
// options.autoSubscribeVideo = true;
@@ -757,30 +665,8 @@ public class AgoraManager {
public void post() {
if (rtcEngine != null) {
// rtcEngine.setParameters("{\"che.video.mobile_1080p\":true}");
// rtcEngine.setClientRole(Constants.CLIENT_ROLE_BROADCASTER);
//
// /*Enable video module*/
// rtcEngine.enableVideo();
// // Setup video encoding configs
// rtcEngine.setVideoEncoderConfiguration(new VideoEncoderConfiguration(
// VD_640x360,
// FRAME_RATE_FPS_15,
// STANDARD_BITRATE,
// ORIENTATION_MODE_ADAPTIVE
// ));
// /*Set up to play remote sound with receiver*/
// rtcEngine.setDefaultAudioRoutetoSpeakerphone(true);
ScreenCaptureParameters screenCaptureParameters = new ScreenCaptureParameters();
// screenCaptureParameters.captureVideo = true;
// screenCaptureParameters.videoCaptureParameters.width = 1440;
// screenCaptureParameters.videoCaptureParameters.height = 1940;
// screenCaptureParameters.videoCaptureParameters.framerate = 15;
// screenCaptureParameters.captureAudio = true;
// screenCaptureParameters.audioCaptureParameters.captureSignalVolume = 50;
//// screenCaptureParameters.videoCaptureParameters.bitrate = 500;
// rtcEngine.startScreenCapture(screenCaptureParameters);
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
@@ -807,26 +693,6 @@ public class AgoraManager {
}
public void setExternalMediaProjection(MediaProjection[] mediaProjection){
rtcEngine.setExternalMediaProjection(mediaProjection[0]);
}
public void isPost(){
if (rtcEngine != null){
ScreenCaptureParameters screenCaptureParameters = new ScreenCaptureParameters();
// 设置新的屏幕共享参数
screenCaptureParameters.captureVideo = true;
screenCaptureParameters.videoCaptureParameters.width = 1280;
screenCaptureParameters.videoCaptureParameters.height = 720;
screenCaptureParameters.videoCaptureParameters.framerate = 30;
// 更新屏幕共享参数
rtcEngine.updateScreenCaptureParameters(screenCaptureParameters);
}
}
public void isMute(int index) {
if (rtcEngine != null) {
}
@@ -838,13 +704,6 @@ public class AgoraManager {
}
}
public void stopMusicPlayer() {
if (musicPlayer != null) {
musicPlayer.stop();
}
}
/**
* 完全销毁实例(只在应用退出时调用)
*/
@@ -967,23 +826,6 @@ public class AgoraManager {
return isLocalAudioEnabled;
}
/**
* 添加事件监听器(用于全局回调)
*/
// public void addEventHandler(IRtcEngineEventHandler handler) {
// if (handler != null && !eventHandlers.contains(handler)) {
// eventHandlers.add(handler);
// }
// }
/**
* 移除事件监听器
*/
// public void removeEventHandler(IRtcEngineEventHandler handler) {
// if (handler != null) {
// eventHandlers.remove(handler);
// }
// }
public void addSoundLevelListener(SoundLevelUpdateListener listener) {
if (soundLevelUpdateListeners != null) {
soundLevelUpdateListeners.add(listener);
@@ -996,6 +838,12 @@ public class AgoraManager {
}
}
public void removeAllSoundLevelListener() {
if (soundLevelUpdateListeners != null) {
soundLevelUpdateListeners.clear();
}
}
public void searchMusic(String keyword, int page) {
if (musicContentCenter == null) {
musicContentCenter = IAgoraMusicContentCenter.create(rtcEngine);

View File

@@ -300,9 +300,6 @@ public class AgoraManagerEx {
};
}
public void joinChannelEx(String token, String channelId, String pkUserIds) {
// if (rtcEngineEx == null) {
// init(CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId());
// }00602f7339ec98947deaeab173599891932IAAe1VwQOurJj57ZCxEJ3SO8VCK6MPKfAjdo5v/oOHPd5BTK+bCVBxwwIgDobHEAn5cDaQQAAQCflwNpAwCflwNpAgCflwNpBACflwNp
if (rtcEngineEx != null) {
options = new ChannelMediaOptions();
options.clientRoleType = Constants.CLIENT_ROLE_BROADCASTER;
@@ -327,12 +324,6 @@ public class AgoraManagerEx {
init(CommonAppContext.getInstance().getCurrentEnvironment().getSwSdkAppId());
}
if (rtcEngineEx != null) {
// RtcConnection connection = new RtcConnection();
// connection.channelId = mRoomId;
// if (connection == null) {
// connection = new RtcConnection();
// connection.channelId = pkRoomId;
// }
rtcEngineEx.muteAllRemoteAudioStreamsEx(enabled, connection);
}
}

View File

@@ -57,72 +57,13 @@ import okhttp3.ResponseBody;
public class AvatarFrameView extends FrameLayout {
private PlaybackManager playbackManager;
private void handleVideoComplete() {
// if (isDestroyed) return;
if (mType == 1) {
if (mBinding != null && mFile != null) {
mBinding.playView.startPlay(mFile); // 循环播放
}
} else {
isPlaying = false;
// playNextFromQueue(); // 播放下一项
currentProcessingCount = Math.max(0, currentProcessingCount - 1);
// 内存检查和清理
if (playQueue.size() % 1 == 0) { // 每处理10个动画检查一次内存
performLightCleanup();
}
// 延迟处理下一个,避免过于频繁
mainHandler.postDelayed(() -> {
smartCheckAndStartPlayback();
}, PROCESSING_DELAY);
// mainHandler.postDelayed(this::playNextFromQueue, 50);
}
}
private void performLightCleanup() {
// 只清理不需要的缓存,保留正在使用的资源
Runtime runtime = Runtime.getRuntime();
long usedMemory = runtime.totalMemory() - runtime.freeMemory();
long maxMemory = runtime.maxMemory();
double memoryUsage = (double) usedMemory / maxMemory;
// 内存使用超过70%时进行轻量级清理
if (memoryUsage > 0.7) {
// 清理SVGA缓存中较旧的项目
if (svgaCache.size() > 1) {
// 保留最近使用的1个缓存项
String oldestKey = null;
for (String key : svgaCache.keySet()) {
if (oldestKey == null) {
oldestKey = key;
}
}
if (oldestKey != null) {
svgaCache.remove(oldestKey);
}
}
// 建议进行垃圾回收
System.gc();
}
}
public enum RenderType {SVGA, MP4}
private RenderType renderType;
// private ExoPlayer exoPlayer;
// private PlayerView playerView;
private SVGAImageView svgaSurface;
private SVGAImageView svgaSurface2;
private GLSurfaceView glSurfaceView;
private final Handler mainHandler = new Handler(Looper.getMainLooper());
private ChannelSplitRenderer1 renderer;
private int mType;//1:循环播放 2:播放一次停止播放
private File mFile;
private final BlockingQueue<PlayItem> playQueue = new LinkedBlockingQueue<>();
private boolean isPlaying = false;
@@ -369,55 +310,7 @@ public class AvatarFrameView extends FrameLayout {
playNextFromQueue();
}
}
// 异步处理URL解析等耗时操作
// ThreadUtils.executeByIo(new ThreadUtils.SimpleTask<String>() {
// @Override
// public String doInBackground() throws Throwable {
// // 在后台线程进行URL有效性检查或其他预处理
// if (url == null || url.isEmpty()) {
// return null;
// }
// return url; // 返回处理后的URL
// }
//
// @Override
// public void onSuccess(String processedUrl) {
// if (processedUrl != null) {
// // 使用post方法确保在下一个UI循环中执行
// mainHandler.post(() -> {
// // 再次检查状态
// if (!isDestroyed && !isPlaying) {
// playQueue.add(new PlayItem(processedUrl, type2));
//// checkAndStartPlayback();
// // 智能检查并开始播放
// smartCheckAndStartPlayback();
// } else {
// // 如果正在播放,添加到队列中
// playQueue.add(new PlayItem(processedUrl, type2));
// }
// });
// }
// }
//
// @Override
// public void onFail(Throwable e) {
// LogUtils.e("Error processing gift URL: " + e.getMessage());
// }
// });
// 添加到播放队列
// playQueue.offer(new PlayItem(url, type2));
// playQueue.add(new PlayItem(url, type2));
Logger.d("AvatarFrameView", "Added to queue, queue size: " + playQueue.size() + ", url: " + url);
// 如果当前没有在播放,则开始播放
// if (!isPlaying) {
// playNextFromQueue();
// }
// 改进播放检查逻辑
// checkAndStartPlayback();
}
private void smartCheckAndStartPlayback() {
@@ -568,14 +461,8 @@ public class AvatarFrameView extends FrameLayout {
playMp4File(file);
} else {
LogUtils.w(TAG, "有缓存2222222222222");
// onPlaybackComplete();
}
});
// 直接播放缓存文件
// if (isTxk) {
// mBinding.playView.setLoop(1);
// }
// mBinding.playView.startPlay(file);
}
}
@@ -619,138 +506,6 @@ public class AvatarFrameView extends FrameLayout {
}
}
// private void downloadAndPlayMp4(String url) {
// String filePath = PathUtils.getInternalAppCachePath() + Md5Utils.getStringMD5(url) + ".mp4";
// File file = new File(filePath);
//
// if (file.exists() && file.length() > 0) {
// playMp4(file);
// mFile = file;
// } else {
// // 删除可能存在的损坏文件
//// if (file.exists()) {
//// file.delete();
//// }
//
// DownloadTask task = new DownloadTask.Builder(url, PathUtils.getInternalAppCachePath()
// , Md5Utils.getStringMD5(url) + ".mp4")
// .setMinIntervalMillisCallbackProcess(300)
// .setPassIfAlreadyCompleted(true)
// .setAutoCallbackToUIThread(true)
// .setConnectionCount(3) // 增加连接数提高稳定性
// .setReadBufferSize(1024 * 8) // 增大缓冲区
// .build();
// if (StatusUtil.isCompleted(task)) {
// playMp4(task.getFile());
// mFile = task.getFile();
// } else if (StatusUtil.isSameTaskPendingOrRunning(task)) {
// Logger.d(TAG, "Task is pending or running, checking if it's stuck");
// // 检查任务是否可能卡住了
// // 添加超时机制,如果任务长时间没有进展,则重新开始
// checkAndHandleStuckTask(task, url);
// } else {
// Logger.d(TAG, "Starting new download task");
// startNewDownload(task, url);
// }
//
//// else if (StatusUtil.isSameTaskPendingOrRunning(task)) {
//// // 如果任务正在进行中,等待完成
//// // 可以通过监听器处理
//// attachToExistingTask(task);
//// } else {
//// task.enqueue(new DownloadListener1() {
//// @Override
//// public void taskStart(@NonNull DownloadTask task, @NonNull Listener1Assist.Listener1Model model) {
//// Logger.e("AvatarFrameView1", model);
//// }
////
//// @Override
//// public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) {
//// Logger.e("AvatarFrameView2", cause);
////
//// }
////
//// @Override
//// public void connected(@NonNull DownloadTask task, int blockCount, long currentOffset, long totalLength) {
//// Logger.e("AvatarFrameView3", blockCount);
//// }
////
//// @Override
//// public void progress(@NonNull DownloadTask task, long currentOffset, long totalLength) {
//// Logger.e("AvatarFrameView4", currentOffset);
//// }
////
//// @Override
//// public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull Listener1Assist.Listener1Model model) {
//// Logger.e("AvatarFrameView5", model);
////// playMp4(task.getFile());
////// mFile = task.getFile();
////// if (cause != null && cause != EndCause.COMPLETED) {
//////// CrashReport.postCatchedException(new RuntimeException("下载任务结束:" + cause == null ? "" : cause.name() + "_realCause:" + realCause == null ? "" : realCause.getMessage()));
////// }
////
//// if (cause == EndCause.COMPLETED) {
//// File downloadedFile = task.getFile();
//// if (downloadedFile != null && downloadedFile.exists() && downloadedFile.length() > 0) {
//// playMp4(downloadedFile);
//// mFile = downloadedFile;
//// } else {
//// Logger.e(TAG, "Downloaded file is invalid");
//// handleDownloadFailure(url, cause, new IOException("Downloaded file is invalid"));
//// }
//// } else {
//// handleDownloadFailure(url, cause, realCause);
//// }
//// }
//// });
//// }
// }
// }
// 添加检查进行中任务的方法
private void attachToExistingTask(DownloadTask task) {
// 为已经在队列中的任务附加监听器
task.enqueue(new DownloadListener1() {
@Override
public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause, @NonNull Listener1Assist.Listener1Model model) {
if (cause == EndCause.COMPLETED) {
playMp4(task.getFile());
mFile = task.getFile();
} else {
isPlaying = false;
playNextFromQueue();
}
}
// 其他回调方法保持空实现或按需处理
@Override
public void taskStart(@NonNull DownloadTask task, @NonNull Listener1Assist.Listener1Model model) {
}
@Override
public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) {
}
@Override
public void connected(@NonNull DownloadTask task, int blockCount, long currentOffset, long totalLength) {
}
@Override
public void progress(@NonNull DownloadTask task, long currentOffset, long totalLength) {
}
});
}
private void playMp4(File file) {
if (file != null) {
mBinding.playView.startPlay(file);
} else {
// showAnim();
// playMp4(file);
// CrashReport.postCatchedException(new RuntimeException("播放MP4失败:File is null"));
}
}
private void handleSVGAComplete(SVGAVideoEntity videoItem, String url) {
if (svgaSurface == null) {
onPlaybackComplete();
@@ -758,7 +513,6 @@ public class AvatarFrameView extends FrameLayout {
}
try {
// 缓存实体(使用弱引用)
// 缓存实体(使用弱引用)
if (svgaCache.size() < MAX_SVGA_CACHE_SIZE) {
svgaCache.put(url, new WeakReference<>(videoItem));
@@ -793,15 +547,6 @@ public class AvatarFrameView extends FrameLayout {
} else {
onPlaybackComplete();
}
// if (Looper.myLooper() != Looper.getMainLooper()) {
// mainHandler.post(() -> {
// isPlaying = false;
// playNextFromQueue();
// });
// } else {
// isPlaying = false;
// playNextFromQueue();
// }
}
});
// 设置循环次数
@@ -838,8 +583,6 @@ public class AvatarFrameView extends FrameLayout {
}
private void playCachedSVGA(SVGAVideoEntity videoItem) {
// if (isDestroyed || svgaSurface == null) return;
try {
SVGADrawable drawable = new SVGADrawable(videoItem, new SVGADynamicEntity());
svgaSurface.setImageDrawable(drawable);
@@ -858,18 +601,14 @@ public class AvatarFrameView extends FrameLayout {
@Override
public void onFinished() {
// if (isDestroyed) return;
if (Looper.myLooper() != Looper.getMainLooper()) {
mainHandler.post(() -> {
isPlaying = false;
// 添加延迟确保状态更新
mainHandler.postDelayed(AvatarFrameView.this::playNextFromQueue, 50);
// playNextFromQueue();
});
} else {
isPlaying = false;
// playNextFromQueue();
mainHandler.postDelayed(AvatarFrameView.this::playNextFromQueue, 50);
}
}
@@ -890,7 +629,6 @@ public class AvatarFrameView extends FrameLayout {
}
private void loadNewSVGA(String url) {
// if (isDestroyed) return;
try {
new SVGAParser(getContext()).parse(new URL(url), new SVGAParser.ParseCompletion() {
@@ -928,8 +666,6 @@ public class AvatarFrameView extends FrameLayout {
}
private void loadSVGA(String url) {
// if (isDestroyed || svgaSurface == null) return;
if (Looper.myLooper() != Looper.getMainLooper()) {
mainHandler.post(() -> loadSVGA(url));
return;
@@ -986,13 +722,6 @@ public class AvatarFrameView extends FrameLayout {
}
});
// svgaSurface.setCallback(new SVGAImageViewCallback() {
// @Override
// public void onAnimationFinished() {
// isPlaying = false;
// playNextFromQueue();
// }
// });
svgaSurface.startAnimation();
}
@@ -1007,65 +736,9 @@ public class AvatarFrameView extends FrameLayout {
}
}
// private void loadMP4(String url) {
// svgaSurface.setVisibility(View.GONE);
// playerView.setVisibility(View.GONE);
//
// glSurfaceView.setVisibility(View.VISIBLE);
// glSurfaceView.onResume();
// glSurfaceView.requestRender();
// // 使用 post 确保 GLSurfaceView 已完成 layout
// glSurfaceView.post(() -> {
// Log.d("@@@", "GLSurfaceView size after layout: " + glSurfaceView.getWidth() + "x" + glSurfaceView.getHeight());
//
// glSurfaceView.onResume();
// glSurfaceView.requestRender();
//
// renderer.setOnSurfaceTextureReadyListener(surfaceTexture -> {
// mainHandler.post(() -> {
// Surface surface = new Surface(surfaceTexture);
//
// MediaItem mediaItem = MediaItem.fromUri(Uri.parse(url));
// exoPlayer.setMediaItem(mediaItem);
// exoPlayer.setVideoSurface(surface);
// exoPlayer.prepare();
// exoPlayer.play();
// Log.d("@@@", "ExoPlayer state after play: " + exoPlayer.getPlaybackState());
// });
// });
// });
// }
private void clearPrevious() {
// 确保在主线程中执行
// if (Looper.myLooper() != Looper.getMainLooper()) {
// mainHandler.post(() -> {
// clearPrevious();
//// }
// });
// return;
// }
try {
// 停止并清理 ExoPlayer
// if (exoPlayer != null) {
// try {
// exoPlayer.stop(); // 这里可能会在错误线程中调用
// exoPlayer.clearVideoSurface();
// } catch (Exception e) {
// Logger.e("Error stopping ExoPlayer: " + e.getMessage());
// // 如果在错误线程中,切换到主线程重试
// mainHandler.post(() -> {
// try {
// if (exoPlayer != null) {
// exoPlayer.stop();
// exoPlayer.clearVideoSurface();
// }
// } catch (Exception ex) {
// Logger.e("Error stopping ExoPlayer on main thread: " + ex.getMessage());
// }
// });
// }
// }
// 停止并清理 SVGA 动画
if (svgaSurface != null && svgaSurface.getDrawable() instanceof SVGADrawable) {
SVGADrawable drawable = (SVGADrawable) svgaSurface.getDrawable();
@@ -1090,15 +763,6 @@ public class AvatarFrameView extends FrameLayout {
} catch (Exception e) {
LogUtils.e(TAG, "Error in clearPrevious: " + e.getMessage());
}
// if (svgaSurface.getDrawable() instanceof SVGADrawable) {
// ((SVGADrawable) svgaSurface.getDrawable()).stop();
// }
// if (playerView != null) playerView.setVisibility(View.GONE);
// if (svgaSurface != null) svgaSurface.setVisibility(View.GONE);
// if (glSurfaceView != null) glSurfaceView.setVisibility(View.GONE);
// mBinding.playView.setVisibility(View.GONE);
}
// 简单的 LRU Cache 实现
@@ -1141,40 +805,6 @@ public class AvatarFrameView extends FrameLayout {
});
}
}).start();
// try {
// // 清理 SVGA 资源
// if (svgaSurface != null && svgaSurface.getDrawable() instanceof SVGADrawable) {
// SVGADrawable drawable = (SVGADrawable) svgaSurface.getDrawable();
// if (drawable != null) {
// try {
// drawable.stop();
// svgaSurface.clearAnimation();
// svgaSurface.setImageDrawable(null);
// } catch (Exception e) {
// LogUtils.e(TAG, "Error releasing SVGA resources: " + e.getMessage());
// }
// }
// }
//
// // 停止并清理播放器
// if (mBinding != null && mBinding.playView != null) {
// mBinding.playView.stopPlay();
// }
//
// // 清理 ExoPlayer 资源
// if (exoPlayer != null) {
// try {
// exoPlayer.stop();
// exoPlayer.clearVideoSurface();
// } catch (Exception e) {
// LogUtils.e(TAG, "Error releasing ExoPlayer resources: " + e.getMessage());
// }
// }
// } catch (Exception e) {
// LogUtils.e(TAG, "Error in releaseResources: " + e.getMessage());
// }
}
/**

View File

@@ -4,14 +4,19 @@ import android.content.Context;
import android.os.CountDownTimer;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.blankj.utilcode.util.LogUtils;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.base.CommonAppContext;
import com.xscm.moduleutil.base.RoomRollModel;
@@ -75,6 +80,9 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
private TextView tv_zhul;
private SVGAParser parser = new SVGAParser(getContext());
public BaseWheatView(Context context) {
this(context, null, 0);
}
@@ -100,7 +108,7 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
mTvNo = findViewById(R.id.tv_no);
iv_on_line = findViewById(R.id.iv_online);/**/
iv_tag_type = findViewById(R.id.iv_tag_type);
tv_zhul=findViewById(R.id.tv_zhul);
tv_zhul = findViewById(R.id.tv_zhul);
setClipChildren(false);
setClipToPadding(false);
oX = mIvGift.getX();
@@ -141,15 +149,12 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
}
/**
* 设置麦位数据
*
* @param bean
*/
@Override
@Subscribe(threadMode = ThreadMode.MAIN)
public void setData(RoomPitBean bean) {
if (!pitNumber.equals(bean.getPit_number())) {
return;
@@ -160,42 +165,33 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
setCardiac(pitBean.getCharm(), getTzbl());
if (bean.getUser_id()!=null && !bean.getUser_id().equals("0") && !bean.getUser_id().isEmpty()) {
if (CommonAppContext.getInstance().getOnlineMap()!=null&&CommonAppContext.getInstance().getOnlineMap().get(bean.getUser_id())!=null) {
if (bean.getUser_id() != null && !bean.getUser_id().equals("0") && !bean.getUser_id().isEmpty()) {
if (CommonAppContext.getInstance().getOnlineMap() != null && CommonAppContext.getInstance().getOnlineMap().get(bean.getUser_id()) != null) {
iv_on_line.setVisibility(CommonAppContext.getInstance().getOnlineMap().get(bean.getUser_id()) == 1 ? GONE : VISIBLE);
}else {
} else {
iv_on_line.setVisibility(GONE);
}
}else {
} else {
iv_on_line.setVisibility(GONE);
}
parser.decodeFromAssets("ripple3695.svga", new SVGAParser.ParseCompletion() {
@Override
public void onComplete(@Nullable SVGAVideoEntity videoItem) {
if (videoItem != null) {
mIvRipple.setVideoItem(videoItem);
}
}
@Override
public void onError() {
Log.e("SVGA", "解析 ripple.svga 失败");
}
});
setPitData(bean);
// if (bean.getIs_online() == 2 && bean.getUser_id()!=null && !bean.getUser_id().equals("0") && !bean.getUser_id().isEmpty()){
// iv_on_line.setVisibility(VISIBLE);
// }else {
// iv_on_line.setVisibility(GONE);
// }
// if (bean.getIs_online() == 0 &&bean.getUser_id() != null && !bean.getUser_id().equals("0") && !bean.getUser_id().isEmpty()) {
// iv_on_line.setVisibility(VISIBLE);
// } else {
// iv_on_line.setVisibility(GONE);
// }
// if (isOn() && bean.getBall_state() == 1) {
// gameImgView.startGame();
// } else {
// gameImgView.overGame();
// }
// String userOnlineStatusBean = SpUtil.getUserOnline();
// if (userOnlineStatusBean!= null){
//// if (userOnlineStatusBean.getUser_id().equals(bean.getUser_id()) && userOnlineStatusBean.getIs_online() == 1){
//// iv_on_line.setVisibility(GONE);
//// }else {
//// iv_on_line.setVisibility(VISIBLE);
//// }
// }
//心动值
//显示心动
if ("1".equals(pitBean.getShutup())) {
@@ -205,15 +201,10 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
}
//自动调节麦位波纹
// if (!TextUtils.isEmpty(bean.getDress_picture())) {
if (mIvRipple!= null) {
if (mIvRipple != null) {
mIvRipple.setScaleX(1.1f);
mIvRipple.setScaleY(1.1f);
}
// } else {
// mIvRipple.setScaleX(0.9f);
// mIvRipple.setScaleY(0.9f);
// }
if (pitNumber.equals("9")) {
iv_tag_type.setImageResource(R.mipmap.zc);
if (mRiv.getLayoutParams() instanceof ConstraintLayout.LayoutParams) {
@@ -250,29 +241,21 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
AgoraManager.getInstance(getContext()).addSoundLevelListener(new SoundLevelUpdateListener() {
@Override
public void onRemoteSoundLevelUpdate(String userId, int soundLevel) {
if (mIvRipple == null)
if (mIvRipple == null)
return;
if (userId.equals(pitBean.getUser_id())) {
if (soundLevel == 0) {
mIvRipple.post(() -> {
mIvRipple.stopAnimation(true);
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(),1);
mIvRipple.setVisibility(INVISIBLE);
});
mIvRipple.pauseAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
mIvRipple.setVisibility(INVISIBLE);
} else {
mIvRipple.setVisibility(VISIBLE);
mIvRipple.post(() -> {
if (!mIvRipple.isAnimating()) {
mIvRipple.startAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(),1);
iv_on_line.setVisibility(GONE);
}
});
mIvRipple.startAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
iv_on_line.setVisibility(GONE);
}
}
}
@Override
@@ -280,50 +263,32 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
if (mIvRipple == null)
return;
if (volume == 0) {
mIvRipple.post(() -> {
mIvRipple.setVisibility(GONE);
});
mIvRipple.setVisibility(GONE);
} else {
mIvRipple.setVisibility(VISIBLE);
mIvRipple.post(() -> {
if (!mIvRipple.isAnimating()) {
mIvRipple.startAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(),1);
iv_on_line.setVisibility(GONE);
}
});
}
}
@Override
public void userJoined(int userId, int elapsd) {
if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
if (pitBean.getUser_id().equals(userId + "")) {
// iv_on_line.setVisibility(GONE);
if (!mIvRipple.isAnimating()) {
mIvRipple.startAnimation();
CommonAppContext.getInstance().onlineMap.put(pitBean.getUser_id(), 1);
iv_on_line.setVisibility(GONE);
}
}
}
@Override
public void userJoined(int userId, int elapsd) {
}
@Override
public void userOffline(int userId, int reason) {
// if (pitBean != null && pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0")) {
// if (pitBean.getUser_id().equals(userId + "")) {
//// iv_on_line.setVisibility(VISIBLE);
// }
// }else if (pitBean.getUser_id()==null || pitBean.getUser_id().equals("0") || pitBean.getUser_id().equals("")){
//// iv_on_line.setVisibility(GONE);
// }
}
});
if (pitBean.getUser_id()==null || pitBean.getUser_id().equals("0") || pitBean.getUser_id().equals("") ){
// iv_on_line.setVisibility(GONE);
}
}
public void setCharm(String charm){
public void setCharm(String charm) {
mCharmView.setSex(pitBean.getSex(), pitBean.getUser_id(), charm, false);
}
@@ -370,27 +335,14 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
}
}
// @Subscribe(threadMode = ThreadMode.MAIN)
public void setOnlineStatus() {
// if (pitBean!=null) {
// if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
// if (pitBean.getUser_id().equals(isOnline.getUser_id())) {
// if (isOnline.getIs_online() == 1) {
// iv_on_line.setVisibility(GONE);
// } else {
// iv_on_line.setVisibility(VISIBLE);
// }
// }
// }
// }
if (pitBean.getUser_id()!=null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
if (CommonAppContext.getInstance().getOnlineMap()!=null&&CommonAppContext.getInstance().getOnlineMap().get(pitBean.getUser_id())!=null) {
if (pitBean.getUser_id() != null && !pitBean.getUser_id().equals("0") && !pitBean.getUser_id().isEmpty()) {
if (CommonAppContext.getInstance().getOnlineMap() != null && CommonAppContext.getInstance().getOnlineMap().get(pitBean.getUser_id()) != null) {
iv_on_line.setVisibility(CommonAppContext.getInstance().getOnlineMap().get(pitBean.getUser_id()) == 1 ? GONE : VISIBLE);
}else {
} else {
iv_on_line.setVisibility(GONE);
}
}else {
} else {
iv_on_line.setVisibility(GONE);
}
}
@@ -445,7 +397,6 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
if (listBean.getUser_id() == null || !listBean.getUser_id().equals(pitBean.getUser_id())) {
return;
}
// ImageUtils.loadImageView(listBean.getPicture(), mIvGift);
WheatGiftAnim.addGift(mIvGift, listBean.getPicture());
}
@@ -459,7 +410,6 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
if (mCharmView != null) {
pitBean.setCharm((rough_number != null && !rough_number.isEmpty()) ? rough_number : "0");
if (pitBean.getUser_id() == null || pitBean.getUser_id().equals("0") || pitBean.getUser_id().equals("")) {
// mCharmView.setVisibility(GONE);
mCharmView.setSex(pitBean.getSex(), pitBean.getUser_id(), pitBean.getCharm(), false);
} else {
mCharmView.setVisibility(VISIBLE);
@@ -727,11 +677,6 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
mIvFace.addData(new FaceBean(roomRollModel.getNumber(), 2));
}
/**
* 球球大作战开球
*
* @param event
*/
/**
* 是否主持
@@ -743,30 +688,4 @@ public abstract class BaseWheatView extends ConstraintLayout implements IBaseWhe
return WHEAT_HOST.equals(pitNumber);
}
// @Override
// public void onRemoteSoundLevelUpdate(String userId, int volume) {
// if (userId.equals(pitBean.getUser_id())) {
// if (volume == 0) {
// mIvRipple.post(() -> {
// mIvRipple.setVisibility(GONE);
// });
// } else {
// mIvRipple.post(() -> {
// if (!mIvRipple.isAnimating()) {
// mIvRipple.startAnimation();
// }
// mIvRipple.setVisibility(VISIBLE);
// });
// }
// if (pitBean.getUser_id().equals(SpUtil.getUserId()) && closePhone) {
// mIvRipple.post(() -> {
// mIvRipple.setVisibility(GONE);
// });
// }
// } else if (userId.equals("0")) {
// mIvRipple.post(() -> {
// mIvRipple.setVisibility(GONE);
// });
// }
// }
}

View File

@@ -23,7 +23,6 @@ public class RoomSingSongWheatView extends BaseWheatView {
public ImageView mIvTagBoss;
public TextView mTvTime;
public TextView tv_time_pk;
public boolean isClickListenerSet = false;
private boolean showBoss;//显示老板标识
public RoomSingSongWheatView(Context context) {
@@ -65,7 +64,6 @@ public class RoomSingSongWheatView extends BaseWheatView {
sex = bean.getSex();
pitBean = bean; // 统一使用参数 bean
stopAndClearAnimation(); // 清理之前的动画资源
if (isOn()) {
handleOnState(bean);
} else {
@@ -73,13 +71,11 @@ public class RoomSingSongWheatView extends BaseWheatView {
}
updateSexIcon();
// updateCharmViewVisibility(bean);
updatePkState(bean);
iv_on_line.setVisibility(GONE);
}
private void handleOnState(RoomPitBean bean) {
mIvRipple.setVisibility(VISIBLE);
mTvName.setText(bean.getNickname());
ImageUtils.loadHeadCC(bean.getAvatar(), mRiv);
@@ -121,7 +117,7 @@ public class RoomSingSongWheatView extends BaseWheatView {
if ("-1".equals(pitNumber)) return "";
if ("9".equals(pitNumber)) return "主持位";
if ("10".equals(pitNumber)) return "嘉宾位";
return pitNumber + "";
return pitNumber + "号位";
}
private void updateSexIcon() {
@@ -149,7 +145,7 @@ public class RoomSingSongWheatView extends BaseWheatView {
tv_time_pk.setVisibility(GONE);
if (isOn()) {
mCharmView.setVisibility(VISIBLE);
}else {
} else {
mCharmView.setVisibility(GONE);
}
}
@@ -176,18 +172,6 @@ public class RoomSingSongWheatView extends BaseWheatView {
private boolean showSexIcon = false;
private String sex;
public boolean isMale() {
return "1".equals(sex);
}
public boolean isFemale() {
return "2".equals(sex);
}
public void setShowSexIcon(boolean show) {
showSexIcon = show;
}
public void checkSex() {
if (isOn()) {
mIvSex.setVisibility(VISIBLE);
@@ -229,14 +213,9 @@ public class RoomSingSongWheatView extends BaseWheatView {
}
}
public void hideMaoziIcon() {
View maozi = findViewById(R.id.iv_maozi);
if (maozi != null) maozi.setVisibility(GONE);
}
// 添加内存释放方法
public void releaseResources() {
stopAndClearAnimation();
// 清理头像加载
if (mRiv != null) {
@@ -263,63 +242,36 @@ public class RoomSingSongWheatView extends BaseWheatView {
}
}
// 停止并清理动画资源
private void stopAndClearAnimation() {
if (mIvRipple != null) {
// mIvRipple.stopAnimation();
mIvRipple.stopAnimation(true);
// 清理SVGA资源避免内存泄漏
// mIvRipple.clear();
}
}
@Override
protected void onDetachedFromWindow() {
// 视图从窗口分离时释放资源
releaseResources();
super.onDetachedFromWindow();
}
@Override
public void onRemoteSoundLevelUpdate(String userId, int soundLevel) {
// 暂无实现
}
@Override
public void onLocalSoundLevelUpdate(int volume) {
if (mIvRipple == null) {
return;
}
if (volume == 0) {
mIvRipple.setVisibility(GONE);
mIvRipple.stopAnimation(true);
} else {
// 增加空指针检查
if (pitBean != null && pitBean.getUser_id() != null &&
pitBean.getUser_id().equals(SpUtil.getUserId()) && closePhone) {
mIvRipple.stopAnimation(true);
} else {
mIvRipple.post(() -> {
mIvRipple.setVisibility(VISIBLE);
mIvRipple.startAnimation();
});
}
}
}
@Override
public void userJoined(int userId, int elapsd) {
// 暂无实现
}
@Override
public void userOffline(int userId, int reason) {
// 暂无实现
}
@Override
public void unRegister(Object obj) {
}
@Override
public void onRemoteSoundLevelUpdate(String userId, int soundLevel) {
}
@Override
public void onLocalSoundLevelUpdate(int volume) {
}
@Override
public void userJoined(int userId, int elapsd) {
}
@Override
public void userOffline(int userId, int reason) {
}
}

View File

@@ -1,6 +1,5 @@
package com.xscm.moduleutil.widget;
import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
@@ -9,17 +8,15 @@ import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import com.google.android.material.snackbar.Snackbar;
import com.hjq.toast.ToastUtils;
import com.xscm.moduleutil.R;
import com.xscm.moduleutil.bean.RoomMessageEvent;
import com.xscm.moduleutil.bean.UserOnlineStatusBean;
import com.xscm.moduleutil.bean.room.RoomPitBean;
import com.xscm.moduleutil.utils.SpUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* @Author lxj$
@@ -466,40 +463,6 @@ public class WheatLayoutSingManager {
}
return null;
}
/**
* 批量刷新多个麦位状态
*/
public void refreshWheatData(List<RoomPitBean> newPitList, List<Integer> changedPits) {
// 检查容器状态
if (container == null || !isContainerValid()) {
return;
}
this.pitList = newPitList;
// 注意:原代码中此方法体为空,如果需要实现请取消注释下面的代码
// for (int pitNumber : changedPits) {
// updateSingleWheat(pitNumber);
// }
}
public void updateSingleOnlineWheat(UserOnlineStatusBean bean) {
// 检查容器状态
if (container == null || !isContainerValid()) {
return;
}
if (pitList == null || pitList.isEmpty()) return;
for (RoomPitBean pitBean : pitList) {
int pitNumber = Integer.parseInt(pitBean.getPit_number());
RoomSingSongWheatView wheatView = findWheatViewByPitNumber(pitNumber);
if (wheatView != null) {
wheatView.setOnlineStatus(); // 刷新数据
}
}
}
// 添加容器状态检查方法
private boolean isContainerValid() {
try {
@@ -513,30 +476,13 @@ public class WheatLayoutSingManager {
// 添加资源清理方法
public void release() {
try {
if (multiWheatViews!=null){
for (RoomSingSongWheatView wheatView : multiWheatViews) {
wheatView.releaseResources();
}
}
if (container != null) {
// 清理所有子视图的资源
// for (int i = 0; i < container.getChildCount(); i++) {
// View child = container.getChildAt(i);
// if (child instanceof LinearLayout) {
// LinearLayout linearLayout = (LinearLayout) child;
// for (int j = 0; j < linearLayout.getChildCount(); j++) {
// View view = linearLayout.getChildAt(j);
// if (view instanceof RoomSingSongWheatView) {
// ((RoomSingSongWheatView) view).releaseResources();
// }
// }
// } else if (child instanceof RoomSingSongWheatView) {
// ((RoomSingSongWheatView) child).releaseResources();
// }
// }
container.removeAllViews();
}
} catch (Exception e) {