From ef0d7e585037a11e678b8f85a596d589833b03b7 Mon Sep 17 00:00:00 2001 From: yutou Date: Wed, 7 Apr 2021 09:59:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=B4=E6=92=AD=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E5=99=A8=EF=BC=8C=E6=AF=8F=E7=A7=92=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E4=B8=8B=E7=9B=B4=E6=92=AD=E7=8A=B6=E6=80=81=E5=8F=8A=E5=BD=95?= =?UTF-8?q?=E5=83=8F=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/bilibili/BiliBili/Live.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index 4ddc7c9..181b238 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -45,7 +45,8 @@ public class Live implements ApplicationContextAware { private BilibiliLiveInfo info; private BilibiliUpInfo upData; private Timer heartBeattimer; - public BiliBiliLiveDatabasesManager danmuManager=null; + public BiliBiliLiveDatabasesManager danmuManager = null; + public Timer checkLiveTimer; @PostConstruct public void init() { @@ -80,6 +81,13 @@ public class Live implements ApplicationContextAware { Live.lives.add(this); updateUpInfo(); com.yutou.bilibili.Tools.Log.i("roomId = " + roomId + ", isLogin = " + isLogin); + checkLiveTimer=new Timer(); + checkLiveTimer.schedule(new TimerTask() { + @Override + public void run() { + checkLive(); + } + },0,1000); } private void updateUpInfo() { @@ -200,7 +208,7 @@ public class Live implements ApplicationContextAware { public void stop() { run = false; client.close(); - if(danmuManager!=null){ + if (danmuManager != null) { danmuManager.close(); } if (SaveLive.getInstance().checkLive(roomId)) { @@ -208,6 +216,9 @@ public class Live implements ApplicationContextAware { } Live.lives.remove(this); com.yutou.bilibili.Tools.Log.i("退出" + roomId + "直播间"); + if(checkLiveTimer!=null){ + checkLiveTimer.cancel(); + } } /** @@ -272,9 +283,9 @@ public class Live implements ApplicationContextAware { } catch (Exception e) { int popular = LiveUtils.bytesToInt2(bytes, 0); info.setPopular(popular); + checkLive(); } } - checkLive(); } catch (Exception e) { e.printStackTrace(); com.yutou.bilibili.Tools.Log.i("----------ERROR----------"); @@ -290,8 +301,8 @@ public class Live implements ApplicationContextAware { if (isLive && upData.getSavelive() == 1) { SaveLive.getInstance().addLive(this); } - if(!isLive&&upData.getSavelive()==1){ - if(SaveLive.getInstance().checkLive(roomId)){ + if (!isLive || upData.getSavelive() == 0) { + if (SaveLive.getInstance().checkLive(roomId)) { SaveLive.getInstance().stop(roomId); } } @@ -324,9 +335,9 @@ public class Live implements ApplicationContextAware { service.addLiveData(liveData); break; case "DANMU_MSG"://普通弹幕 - JSONArray infoData=json.getJSONArray("info"); + JSONArray infoData = json.getJSONArray("info"); danmu = json.getJSONArray("info").getString(1); - DanmuData danmuData=new DanmuData(); + DanmuData danmuData = new DanmuData(); danmuData.setModel(infoData.getJSONArray(0).getInteger(1)); danmuData.setFontSize(infoData.getJSONArray(0).getInteger(2)); danmuData.setFontColor(infoData.getJSONArray(0).getInteger(3));