解决直播右上角乱闪

优化epg匹配逻辑
还原正常打包gradle
pull/142/head
21561 1 year ago
parent 1d4b7d602d
commit cba86340ae
  1. 106
      app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java
  2. 45
      app/src/main/res/layout/activity_live_play.xml
  3. 2
      gradle.properties

@ -9,7 +9,6 @@ import android.content.Context;
import android.net.Uri;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.util.Base64;
import android.util.Log;
import android.view.Gravity;
@ -79,7 +78,6 @@ import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
@ -127,7 +125,7 @@ public class LivePlayActivity extends BaseActivity {
//EPG by 龍
private static LiveChannelItem channel_Name = null;
private static Hashtable hsEpg = new Hashtable();
private static Hashtable<String, ArrayList<Epginfo>> hsEpg = new Hashtable();
private CountDownTimer countDownTimer;
// private CountDownTimer countDownTimerRightTop;
private View ll_right_top_loading;
@ -226,7 +224,7 @@ public class LivePlayActivity extends BaseActivity {
tv_curepg_left = (TextView) findViewById(R.id.tv_current_program);//当前节目
tv_nextepg_left= (TextView) findViewById(R.id.tv_current_program);//下一节目
ll_epg = (RelativeLayout) findViewById(R.id.ll_epg);
tv_right_top_tipnetspeed = (TextView)findViewById(R.id.tv_right_top_tipnetspeed);
// tv_right_top_tipnetspeed = (TextView)findViewById(R.id.tv_right_top_tipnetspeed);
tv_right_top_channel_name = (TextView)findViewById(R.id.tv_right_top_channel_name);
tv_right_top_epg_name = (TextView)findViewById(R.id.tv_right_top_epg_name);
// tv_right_top_type = (TextView)findViewById(R.id.tv_right_top_type);
@ -323,18 +321,10 @@ public class LivePlayActivity extends BaseActivity {
if (!fromuser) {
return;
}
if(fromuser){
if(countDownTimer!=null){
mVideoView.seekTo(progress);
countDownTimer.cancel();
countDownTimer.start();
}
/*
long duration = mControlWrapper.getDuration();
long newPosition = (duration * progress) / seekBar.getMax();
if (mCurrentTime != null)
mCurrentTime.setText(stringForTime((int) newPosition));*/
if(countDownTimer!=null){
mVideoView.seekTo(progress);
countDownTimer.cancel();
countDownTimer.start();
}
}
@ -406,33 +396,52 @@ public class LivePlayActivity extends BaseActivity {
}
}
private String getFirstPartBeforeSpace(String str) {
if (str == null || str.isEmpty()) {
return str;
}
int spaceIndex = str.indexOf(' ');
if (spaceIndex == -1) {
return str;
} else {
return str.substring(0, spaceIndex);
}
}
public void getEpg(Date date) {
String channelName = channel_Name.getChannelName();
String channelNameReal = getFirstPartBeforeSpace(channelName);
@SuppressLint("SimpleDateFormat") SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy-MM-dd");
timeFormat.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
String[] epgInfo = EpgUtil.getEpgInfo(channelName);
String epgTagName = channelName;
String[] epgInfo = EpgUtil.getEpgInfo(channelNameReal);
String epgTagName = channelNameReal;
updateChannelIcon(channelName, epgInfo == null ? null : epgInfo[0]);
if (epgInfo != null && !epgInfo[1].isEmpty()) {
epgTagName = epgInfo[1];
}
epgListAdapter.CanBack(currentLiveChannelItem.getinclude_back());
String url;
if(epgStringAddress.contains("{name}") && epgStringAddress.contains("{date}")){
url= epgStringAddress.replace("{name}",URLEncoder.encode(epgTagName)).replace("{date}",timeFormat.format(date));
}else {
url= epgStringAddress + "?ch="+ URLEncoder.encode(epgTagName) + "&date=" + timeFormat.format(date);
}
String savedEpgKey = channelName + "_" + Objects.requireNonNull(liveEpgDateAdapter.getItem(liveEpgDateAdapter.getSelectedIndex())).getDatePresented();
if (hsEpg.containsKey(savedEpgKey)){
showEpg(date, hsEpg.get(savedEpgKey));
showBottomEpg();
return;
}
UrlHttpUtil.get(url, new CallBackUtil.CallBackString() {
public void onFailure(int i, String str) {
showEpg(date, new ArrayList());
showBottomEpg();
// showEpg(date, new ArrayList<>());
// showBottomEpg();
}
public void onResponse(String paramString) {
ArrayList arrayList = new ArrayList();
LOG.i("echo-epgTagName:"+channelNameReal);
ArrayList<Epginfo> arrayList = new ArrayList<Epginfo>();
try {
if (paramString.contains("epg_data")) {
final JSONArray jSONArray = new JSONObject(paramString).optJSONArray("epg_data");
@ -441,17 +450,14 @@ public class LivePlayActivity extends BaseActivity {
JSONObject jSONObject = jSONArray.getJSONObject(b);
Epginfo epgbcinfo = new Epginfo(date,jSONObject.optString("title"), date, jSONObject.optString("start"), jSONObject.optString("end"),b);
arrayList.add(epgbcinfo);
// Log.d("EPG信息:", day +" "+ jSONObject.optString("start") +" - "+jSONObject.optString("end") + " " +jSONObject.optString("title"));
}
}
} catch (JSONException jSONException) {
jSONException.printStackTrace();
}
hsEpg.put(savedEpgKey, arrayList);
showEpg(date, arrayList);
String savedEpgKey = channelName + "_" + liveEpgDateAdapter.getItem(liveEpgDateAdapter.getSelectedIndex()).getDatePresented();
if (!hsEpg.contains(savedEpgKey))
hsEpg.put(savedEpgKey, arrayList);
showBottomEpg();
}
});
@ -472,27 +478,36 @@ public class LivePlayActivity extends BaseActivity {
tip_epg2.setText("开源测试软件");
tv_next_program_name.setText("");
String savedEpgKey = channel_Name.getChannelName() + "_" + Objects.requireNonNull(liveEpgDateAdapter.getItem(liveEpgDateAdapter.getSelectedIndex())).getDatePresented();
if (hsEpg.containsKey(savedEpgKey)) {
ArrayList arrayList = (ArrayList) hsEpg.get(savedEpgKey);
ArrayList<Epginfo> arrayList = hsEpg.get(savedEpgKey);
if (arrayList != null && arrayList.size() > 0) {
Date date = new Date();
int size = arrayList.size() - 1;
boolean hasInfo = false;
while (size >= 0) {
if (date.after(((Epginfo) arrayList.get(size)).startdateTime) & date.before(((Epginfo) arrayList.get(size)).enddateTime)) {
tip_epg1.setText(((Epginfo) arrayList.get(size)).start + "-" + ((Epginfo) arrayList.get(size)).end);
tv_current_program_name.setText(((Epginfo) arrayList.get(size)).title);
if (date.after((arrayList.get(size)).startdateTime) & date.before((arrayList.get(size)).enddateTime)) {
tip_epg1.setText((arrayList.get(size)).start + "-" + (arrayList.get(size)).end);
tv_current_program_name.setText((arrayList.get(size)).title);
if (size != arrayList.size() - 1) {
tip_epg2.setText(((Epginfo) arrayList.get(size + 1)).start + "-" + ((Epginfo) arrayList.get(size + 1)).end);
tv_next_program_name.setText(((Epginfo) arrayList.get(size + 1)).title);
tip_epg2.setText((arrayList.get(size + 1)).start + "-" + (arrayList.get(size + 1)).end);
tv_next_program_name.setText((arrayList.get(size + 1)).title);
} else {
tip_epg2.setText("00:00-23:59");
tip_epg2.setText((arrayList.get(size)).end+"-23:59");
tv_next_program_name.setText("精彩节目-暂无节目预告信息");
}
hasInfo=true;
break;
} else {
size--;
}
}
if(!hasInfo){
tip_epg1.setText("00:00-"+(arrayList.get(0)).start);
tv_current_program_name.setText("精彩节目-暂无节目预告信息");
tip_epg2.setText((arrayList.get(0)).start + "-" + (arrayList.get(0)).end);
tv_next_program_name.setText((arrayList.get(0)).title);
}
}
epgListAdapter.CanBack(currentLiveChannelItem.getinclude_back());
epgListAdapter.setNewData(arrayList);
@ -500,24 +515,27 @@ public class LivePlayActivity extends BaseActivity {
int selectedIndex = liveEpgDateAdapter.getSelectedIndex();
if (selectedIndex < 0)
getEpg(new Date());
else
getEpg(liveEpgDateAdapter.getData().get(selectedIndex).getDateParamVal());
}
if (countDownTimer != null) {
countDownTimer.cancel();
}
if(!tip_epg1.getText().equals("暂无信息")){
ll_right_top_loading.setVisibility(View.VISIBLE);
ll_epg.setVisibility(View.VISIBLE);
countDownTimer = new CountDownTimer(postTimeout, 1000) {//底部epg隐藏时间设定
public void onTick(long j) {
}
public void onFinish() {
ll_right_top_loading.setVisibility(View.GONE);
// ll_right_top_huikan.setVisibility(View.GONE);
ll_epg.setVisibility(View.GONE);
}
};
countDownTimer.start();
}else {
ll_right_top_loading.setVisibility(View.GONE);
ll_right_top_huikan.setVisibility(View.GONE);
ll_epg.setVisibility(View.GONE);
}
if (channel_Name == null || channel_Name.getSourceNum() <= 0) {
@ -527,18 +545,6 @@ public class LivePlayActivity extends BaseActivity {
}
tv_right_top_channel_name.setText(channel_Name.getChannelName());
tv_right_top_epg_name.setText(channel_Name.getChannelName());
Handler handler = new Handler(Looper.getMainLooper());
ll_right_top_loading.setVisibility(View.VISIBLE);
// 延迟5秒后执行隐藏操作
handler.postDelayed(new Runnable() {
@Override
public void run() {
ll_right_top_loading.setVisibility(View.GONE);
ll_right_top_huikan.setVisibility(View.GONE);
}
}, postTimeout);
}
}
@ -1747,7 +1753,7 @@ public class LivePlayActivity extends BaseActivity {
};
private void showNetSpeed() {
tv_right_top_tipnetspeed.setVisibility(View.VISIBLE);
// tv_right_top_tipnetspeed.setVisibility(View.VISIBLE);
if (Hawk.get(HawkConfig.LIVE_SHOW_NET_SPEED, false)) {
mHandler.post(mUpdateNetSpeedRun);
tvNetSpeed.setVisibility(View.VISIBLE);
@ -1763,7 +1769,7 @@ public class LivePlayActivity extends BaseActivity {
if (mVideoView == null) return;
String speed = PlayerHelper.getDisplaySpeed(mVideoView.getTcpSpeed());
tvNetSpeed.setText(speed);
tv_right_top_tipnetspeed.setText(speed);
// tv_right_top_tipnetspeed.setText(speed);
mHandler.postDelayed(this, 1000);
}
};

@ -718,66 +718,35 @@
<!--右上角动态状态栏-->
<RelativeLayout
android:layout_gravity="center|right|top"
android:orientation="vertical"
android:id="@+id/ll_right_top_loading"
android:background="@drawable/shape_user_search"
android:layout_width="@dimen/vs_240"
android:layout_height="@dimen/vs_70"
android:layout_marginTop="25mm"
android:layout_marginRight="25mm"
android:minWidth="270px">
<ImageView
android:id="@+id/iv_circle_bg"
android:layout_width="@dimen/vs_40"
android:layout_height="@dimen/vs_40"
android:layout_marginRight="@dimen/vs_10"
android:src="@drawable/app_icon"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
<ImageView
android:layout_width="@dimen/vs_40"
android:layout_height="@dimen/vs_40"
android:layout_margin="@dimen/vs_10"
android:layout_alignLeft="@+id/iv_circle_bg"
android:layout_alignTop="@+id/iv_circle_bg"
android:layout_alignRight="@+id/iv_circle_bg"
android:layout_alignBottom="@+id/iv_circle_bg" />
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/vs_10"
android:src="@drawable/app_icon" />
<com.github.tvbox.osc.ui.tv.widget.MarqueeTextView
android:id="@+id/tv_right_top_channel_name"
android:layout_width="@dimen/vs_150"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_toStartOf="@+id/iv_circle_bg"
android:layout_toLeftOf="@+id/iv_circle_bg"
android:ellipsize="marquee"
android:gravity="center"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="测试频道"
android:textColor="#FFFCFFFF"
android:textSize="@dimen/vs_30" />
<TextView
android:id="@+id/tv_right_top_tipnetspeed"
android:layout_width="@dimen/vs_150"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
android:layout_marginEnd="@dimen/vs_5"
android:layout_marginRight="@dimen/vs_5"
android:layout_toStartOf="@+id/iv_circle_bg"
android:layout_toLeftOf="@+id/iv_circle_bg"
android:gravity="center"
android:singleLine="true"
android:text=""
tools:text="0Kb/s"
android:textColor="#FFFCFFFF"
android:textSize="@dimen/vs_20" />
android:textSize="@dimen/vs_28"
android:layout_toLeftOf="@id/iv_circle_bg"
android:layout_centerVertical="true"
android:layout_marginRight="10dp" /> <!-- 增加右边距,让名字更靠左 -->
</RelativeLayout>

@ -18,4 +18,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
IsDebug=true
#org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED
org.gradle.jvmargs=-Xmx2048m --add-opens java.base/java.io=ALL-UNNAMED

Loading…
Cancel
Save