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

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 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));