在获取弹幕时抛异常后尝试关闭数据库
This commit is contained in:
parent
52e4312a32
commit
3f10e19e50
@ -89,36 +89,42 @@ public class LiveDanmuService {
|
|||||||
public LiveVideoDanmu getDanmu(String roomId, String videoId, int page) {
|
public LiveVideoDanmu getDanmu(String roomId, String videoId, int page) {
|
||||||
LiveVideoDanmu danmus = new LiveVideoDanmu();
|
LiveVideoDanmu danmus = new LiveVideoDanmu();
|
||||||
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId));
|
BiliLiveDatabase liveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig(roomId));
|
||||||
LiveVideoDatabaseBean videoBean = liveDatabase.getVideo(videoId);
|
try {
|
||||||
if (videoBean == null) {
|
LiveVideoDatabaseBean videoBean = liveDatabase.getVideo(videoId);
|
||||||
return new LiveVideoDanmu();
|
if (videoBean == null) {
|
||||||
}
|
return new LiveVideoDanmu();
|
||||||
long startTime = videoBean.getStartTime().getTime();
|
}
|
||||||
long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime();
|
long startTime = videoBean.getStartTime().getTime();
|
||||||
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class);
|
long endTime = videoBean.getStopTime() == null ? System.currentTimeMillis() : videoBean.getStopTime().getTime();
|
||||||
|
List<LiveSuperChatDatabaseBean> superChatList = liveDatabase.getOfTime(startTime, endTime, LiveSuperChatDatabaseBean.class);
|
||||||
|
|
||||||
long count = liveDatabase.getCount(new LiveDanmuDatabaseBean().getTableName());
|
long count = liveDatabase.getCount(new LiveDanmuDatabaseBean().getTableName());
|
||||||
int pageSize = 10000;
|
int pageSize = 10000;
|
||||||
int pageCount = (int) Math.ceil((double) count / pageSize);
|
int pageCount = (int) Math.ceil((double) count / pageSize);
|
||||||
|
|
||||||
List<LiveVideoDanmu.Danmu> danmuList = liveDatabase.getOfTime(startTime, endTime, page, pageSize, LiveDanmuDatabaseBean.class)
|
List<LiveVideoDanmu.Danmu> danmuList = liveDatabase.getOfTime(startTime, endTime, page, pageSize, LiveDanmuDatabaseBean.class)
|
||||||
.stream()
|
.stream()
|
||||||
.map(item -> createDanmu(item, startTime))
|
.map(item -> createDanmu(item, startTime))
|
||||||
.filter(item-> item.getTime()>=0)
|
.filter(item -> item.getTime() >= 0)
|
||||||
.toList();
|
.toList();
|
||||||
danmus.getDanmu().addAll(danmuList);
|
danmus.getDanmu().addAll(danmuList);
|
||||||
danmus.setDanmuCount(count);
|
danmus.setDanmuCount(count);
|
||||||
if (page < pageCount) {
|
if (page < pageCount) {
|
||||||
danmus.setNextDanmu(true);
|
danmus.setNextDanmu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (LiveSuperChatDatabaseBean bean : superChatList) {
|
||||||
|
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean);
|
||||||
|
danmus.getSuperChat().add(superChat);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(e);
|
||||||
|
} finally {
|
||||||
|
liveDatabase.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (LiveSuperChatDatabaseBean bean : superChatList) {
|
|
||||||
LiveVideoDanmu.SuperChat superChat = new LiveVideoDanmu.SuperChat(startTime, bean);
|
|
||||||
danmus.getSuperChat().add(superChat);
|
|
||||||
}
|
|
||||||
|
|
||||||
liveDatabase.close();
|
|
||||||
return danmus;
|
return danmus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user