新增直播定时器,每秒检测下直播状态及录像状态

This commit is contained in:
yutou 2021-04-07 09:59:01 +08:00
parent b078e5f9b5
commit ef0d7e5850

View File

@ -45,7 +45,8 @@ public class Live implements ApplicationContextAware {
private BilibiliLiveInfo info; private BilibiliLiveInfo info;
private BilibiliUpInfo upData; private BilibiliUpInfo upData;
private Timer heartBeattimer; private Timer heartBeattimer;
public BiliBiliLiveDatabasesManager danmuManager=null; public BiliBiliLiveDatabasesManager danmuManager = null;
public Timer checkLiveTimer;
@PostConstruct @PostConstruct
public void init() { public void init() {
@ -80,6 +81,13 @@ public class Live implements ApplicationContextAware {
Live.lives.add(this); Live.lives.add(this);
updateUpInfo(); updateUpInfo();
com.yutou.bilibili.Tools.Log.i("roomId = " + roomId + ", isLogin = " + isLogin); 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() { private void updateUpInfo() {
@ -200,7 +208,7 @@ public class Live implements ApplicationContextAware {
public void stop() { public void stop() {
run = false; run = false;
client.close(); client.close();
if(danmuManager!=null){ if (danmuManager != null) {
danmuManager.close(); danmuManager.close();
} }
if (SaveLive.getInstance().checkLive(roomId)) { if (SaveLive.getInstance().checkLive(roomId)) {
@ -208,6 +216,9 @@ public class Live implements ApplicationContextAware {
} }
Live.lives.remove(this); Live.lives.remove(this);
com.yutou.bilibili.Tools.Log.i("退出" + roomId + "直播间"); com.yutou.bilibili.Tools.Log.i("退出" + roomId + "直播间");
if(checkLiveTimer!=null){
checkLiveTimer.cancel();
}
} }
/** /**
@ -272,9 +283,9 @@ public class Live implements ApplicationContextAware {
} catch (Exception e) { } catch (Exception e) {
int popular = LiveUtils.bytesToInt2(bytes, 0); int popular = LiveUtils.bytesToInt2(bytes, 0);
info.setPopular(popular); info.setPopular(popular);
}
}
checkLive(); checkLive();
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
com.yutou.bilibili.Tools.Log.i("----------ERROR----------"); com.yutou.bilibili.Tools.Log.i("----------ERROR----------");
@ -290,8 +301,8 @@ public class Live implements ApplicationContextAware {
if (isLive && upData.getSavelive() == 1) { if (isLive && upData.getSavelive() == 1) {
SaveLive.getInstance().addLive(this); SaveLive.getInstance().addLive(this);
} }
if(!isLive&&upData.getSavelive()==1){ if (!isLive || upData.getSavelive() == 0) {
if(SaveLive.getInstance().checkLive(roomId)){ if (SaveLive.getInstance().checkLive(roomId)) {
SaveLive.getInstance().stop(roomId); SaveLive.getInstance().stop(roomId);
} }
} }
@ -324,9 +335,9 @@ public class Live implements ApplicationContextAware {
service.addLiveData(liveData); service.addLiveData(liveData);
break; break;
case "DANMU_MSG"://普通弹幕 case "DANMU_MSG"://普通弹幕
JSONArray infoData=json.getJSONArray("info"); JSONArray infoData = json.getJSONArray("info");
danmu = json.getJSONArray("info").getString(1); danmu = json.getJSONArray("info").getString(1);
DanmuData danmuData=new DanmuData(); DanmuData danmuData = new DanmuData();
danmuData.setModel(infoData.getJSONArray(0).getInteger(1)); danmuData.setModel(infoData.getJSONArray(0).getInteger(1));
danmuData.setFontSize(infoData.getJSONArray(0).getInteger(2)); danmuData.setFontSize(infoData.getJSONArray(0).getInteger(2));
danmuData.setFontColor(infoData.getJSONArray(0).getInteger(3)); danmuData.setFontColor(infoData.getJSONArray(0).getInteger(3));