直播菜单多源切换;

pull/139/head
jun 1 year ago
parent a200897508
commit 5469f7456f
  1. 153
      app/src/main/java/com/github/tvbox/osc/api/ApiConfig.java
  2. 2
      app/src/main/java/com/github/tvbox/osc/player/controller/VodController.java
  3. 63
      app/src/main/java/com/github/tvbox/osc/ui/activity/LivePlayActivity.java
  4. 9
      app/src/main/java/com/github/tvbox/osc/ui/activity/PlayActivity.java
  5. 13
      app/src/main/java/com/github/tvbox/osc/ui/fragment/PlayFragment.java
  6. 4
      app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java

@ -375,80 +375,15 @@ public class ApiConfig {
setDefaultParse(parseBeanList.get(0));
}
// 直播源
liveChannelGroupList.clear(); //修复从后台切换重复加载频道列表
try {
JsonObject livesOBJ = infoJson.get("lives").getAsJsonArray().get(0).getAsJsonObject();
String lives = livesOBJ.toString();
int index = lives.indexOf("proxy://");
if (index != -1) {
int endIndex = lives.lastIndexOf("\"");
String url = lives.substring(index, endIndex);
url = DefaultConfig.checkReplaceProxy(url);
//clan
String extUrl = Uri.parse(url).getQueryParameter("ext");
if (extUrl != null && !extUrl.isEmpty()) {
String extUrlFix;
if(extUrl.startsWith("http") || extUrl.startsWith("clan://")){
extUrlFix = extUrl;
}else {
extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
}
// System.out.println("extUrlFix :"+extUrlFix);
if (extUrlFix.startsWith("clan://")) {
extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
}
extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
url = url.replace(extUrl, extUrlFix);
}
// System.out.println("urlLive :"+url);
//设置epg
if(livesOBJ.has("epg")){
String epg =livesOBJ.get("epg").getAsString();
Hawk.put(HawkConfig.EPG_URL,epg);
}
//直播播放器类型
if(livesOBJ.has("playerType")){
String livePlayType =livesOBJ.get("playerType").getAsString();
Hawk.put(HawkConfig.LIVE_PLAY_TYPE,livePlayType);
}
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setGroupName(url);
liveChannelGroupList.add(liveChannelGroup);
} else {
if(!lives.contains("type")){
loadLives(infoJson.get("lives").getAsJsonArray());
}else {
JsonObject fengMiLives = infoJson.get("lives").getAsJsonArray().get(0).getAsJsonObject();
String type=fengMiLives.get("type").getAsString();
if(type.equals("0")){
String url =fengMiLives.get("url").getAsString();
//设置epg
if(fengMiLives.has("epg")){
String epg =fengMiLives.get("epg").getAsString();
Hawk.put(HawkConfig.EPG_URL,epg);
}
//直播播放器类型
if(livesOBJ.has("playerType")){
String livePlayType =livesOBJ.get("playerType").getAsString();
Hawk.put(HawkConfig.LIVE_PLAY_TYPE,livePlayType);
}
if(url.startsWith("http")){
url = Base64.encodeToString(url.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
}
url ="http://127.0.0.1:9978/proxy?do=live&type=txt&ext="+url;
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setGroupName(url);
liveChannelGroupList.add(liveChannelGroup);
}
}
}
} catch (Throwable th) {
th.printStackTrace();
if(infoJson.has("lives")){
// Hawk.put(HawkConfig.LIVE_GROUP_INDEX,0);
JsonArray lives_groups=infoJson.get("lives").getAsJsonArray();
int live_group_index=Hawk.get(HawkConfig.LIVE_GROUP_INDEX,0);
JsonObject livesOBJ = lives_groups.get(live_group_index).getAsJsonObject();
Hawk.put(HawkConfig.LIVE_GROUP_LIST,lives_groups);
loadLiveApi(livesOBJ);
}
//video parse rule for host
if (infoJson.has("rules")) {
VideoParseRuler.clearRule();
@ -609,6 +544,78 @@ public class ApiConfig {
}
}
public void loadLiveApi(JsonObject livesOBJ) {
// 直播源
liveChannelGroupList.clear(); //修复从后台切换重复加载频道列表
try {
String type= livesOBJ.get("type").getAsString();
String lives = livesOBJ.toString();
int index = lives.indexOf("proxy://");
if (index != -1) {
int endIndex = lives.lastIndexOf("\"");
String url = lives.substring(index, endIndex);
url = DefaultConfig.checkReplaceProxy(url);
//clan
String extUrl = Uri.parse(url).getQueryParameter("ext");
if (extUrl != null && !extUrl.isEmpty()) {
String extUrlFix;
if(extUrl.startsWith("http") || extUrl.startsWith("clan://")){
extUrlFix = extUrl;
}else {
extUrlFix = new String(Base64.decode(extUrl, Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP), "UTF-8");
}
// System.out.println("extUrlFix :"+extUrlFix);
// if (extUrlFix.startsWith("clan://")) {
// extUrlFix = clanContentFix(clanToAddress(apiUrl), extUrlFix);
// }
extUrlFix = Base64.encodeToString(extUrlFix.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
url = url.replace(extUrl, extUrlFix);
}
// System.out.println("urlLive :"+url);
//设置epg
if(livesOBJ.has("epg")){
String epg =livesOBJ.get("epg").getAsString();
Hawk.put(HawkConfig.EPG_URL,epg);
}
//直播播放器类型
if(livesOBJ.has("playerType")){
String livePlayType =livesOBJ.get("playerType").getAsString();
Hawk.put(HawkConfig.LIVE_PLAY_TYPE,livePlayType);
}
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setGroupName(url);
liveChannelGroupList.add(liveChannelGroup);
} else {
if(type.equals("0")){
String url = livesOBJ.get("url").getAsString();
//设置epg
if(livesOBJ.has("epg")){
String epg = livesOBJ.get("epg").getAsString();
Hawk.put(HawkConfig.EPG_URL,epg);
}
//直播播放器类型
if(livesOBJ.has("playerType")){
String livePlayType =livesOBJ.get("playerType").getAsString();
Hawk.put(HawkConfig.LIVE_PLAY_TYPE,livePlayType);
}
if(url.startsWith("http")){
url = Base64.encodeToString(url.getBytes("UTF-8"), Base64.DEFAULT | Base64.URL_SAFE | Base64.NO_WRAP);
}
url ="http://127.0.0.1:9978/proxy?do=live&type=txt&ext="+url;
LiveChannelGroup liveChannelGroup = new LiveChannelGroup();
liveChannelGroup.setGroupName(url);
liveChannelGroupList.add(liveChannelGroup);
}
}
} catch (Throwable th) {
th.printStackTrace();
}
}
public String getSpider() {
return spider;
}

@ -1024,7 +1024,7 @@ public class VodController extends BaseController {
//尝试去bom
public String getWebPlayUrlIfNeeded(String webPlayUrl) {
if (webPlayUrl != null && webPlayUrl.contains(".m3u8")) {
if (webPlayUrl != null && !webPlayUrl.contains("127.0.0.1:9978") && webPlayUrl.contains(".m3u8")) {
try {
String urlEncode = URLEncoder.encode(webPlayUrl, "UTF-8");
LOG.i("echo-BOM-------");

@ -49,9 +49,7 @@ import com.github.tvbox.osc.ui.adapter.LiveSettingGroupAdapter;
import com.github.tvbox.osc.ui.adapter.LiveSettingItemAdapter;
import com.github.tvbox.osc.ui.adapter.MyEpgAdapter;
import com.github.tvbox.osc.ui.dialog.LivePasswordDialog;
import com.github.tvbox.osc.ui.tv.widget.ChannelListView;
import com.github.tvbox.osc.ui.tv.widget.ViewObj;
import com.github.tvbox.osc.util.EpgNameFuzzyMatch;
import com.github.tvbox.osc.util.EpgUtil;
import com.github.tvbox.osc.util.FastClickCheckUtil;
import com.github.tvbox.osc.util.HawkConfig;
@ -60,9 +58,10 @@ import com.github.tvbox.osc.util.PlayerHelper;
import com.github.tvbox.osc.util.live.TxtSubscribe;
import com.github.tvbox.osc.util.urlhttp.CallBackUtil;
import com.github.tvbox.osc.util.urlhttp.UrlHttpUtil;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.AbsCallback;
import com.lzy.okgo.model.Response;
@ -75,8 +74,6 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.FileOutputStream;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -665,6 +662,7 @@ public class LivePlayActivity extends BaseActivity {
}
private void showChannelList() {
if(liveChannelGroupList.isEmpty()) return;
if (tvRightSettingLayout.getVisibility() == View.VISIBLE) {
mHandler.removeCallbacks(mHideSettingLayoutRun);
mHandler.post(mHideSettingLayoutRun);
@ -1181,7 +1179,7 @@ public class LivePlayActivity extends BaseActivity {
case VideoView.STATE_ERROR:
case VideoView.STATE_PLAYBACK_COMPLETED:
mHandler.removeCallbacks(mConnectTimeoutChangeSourceRun);
mHandler.postDelayed(mConnectTimeoutChangeSourceRun, 6000);
mHandler.postDelayed(mConnectTimeoutChangeSourceRun, 1500);
break;
case VideoView.STATE_PREPARING:
case VideoView.STATE_BUFFERING:
@ -1484,7 +1482,7 @@ public class LivePlayActivity extends BaseActivity {
case 3://超时换源
Hawk.put(HawkConfig.LIVE_CONNECT_TIMEOUT, position);
break;
case 4://超时换源
case 4://偏好设置
boolean select = false;
switch (position) {
case 0:
@ -1508,6 +1506,23 @@ public class LivePlayActivity extends BaseActivity {
}
liveSettingItemAdapter.selectItem(position, select, false);
break;
case 5://多源切换
//TODO
if(position==Hawk.get(HawkConfig.LIVE_GROUP_INDEX, 0))break;
liveSettingItemAdapter.selectItem(position, true, true);
JsonArray live_groups=Hawk.get(HawkConfig.LIVE_GROUP_LIST,new JsonArray());
JsonObject livesOBJ = live_groups.get(position).getAsJsonObject();
String type= livesOBJ.get("type").getAsString();
if(!type.equals("0")){
Toast.makeText(App.getInstance(), "暂不支持该直播类型", Toast.LENGTH_SHORT).show();
break;
}
Hawk.put(HawkConfig.LIVE_GROUP_INDEX, position);
mVideoView.release();
ApiConfig.get().loadLiveApi(livesOBJ);
// init();
recreate();
return;
}
mHandler.removeCallbacks(mHideSettingLayoutRun);
mHandler.postDelayed(mHideSettingLayoutRun, 6000);
@ -1516,6 +1531,7 @@ public class LivePlayActivity extends BaseActivity {
private void initLiveChannelList() {
List<LiveChannelGroup> list = ApiConfig.get().getChannelGroupList();
if (list.isEmpty()) {
Hawk.put(HawkConfig.LIVE_GROUP_INDEX, 0);
Toast.makeText(App.getInstance(), "频道列表为空", Toast.LENGTH_SHORT).show();
finish();
return;
@ -1542,6 +1558,8 @@ public class LivePlayActivity extends BaseActivity {
return;
}
showLoading();
LOG.i("echo-live-url:"+url);
OkGo.<String>get(url).execute(new AbsCallback<String>() {
@Override
@ -1575,6 +1593,17 @@ public class LivePlayActivity extends BaseActivity {
}
});
}
@Override
public void onError(Response<String> response) {
Toast.makeText(App.getInstance(), "加载错误,自动回退到主页", Toast.LENGTH_SHORT).show();
Hawk.put(HawkConfig.LIVE_GROUP_INDEX, 0);
mHandler.post(new Runnable() {
@Override
public void run() {
jumpActivity(HomeActivity.class);
}
});
}
});
}
@ -1615,18 +1644,35 @@ public class LivePlayActivity extends BaseActivity {
}
private void initLiveSettingGroupList() {
ArrayList<String> groupNames = new ArrayList<>(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置"));
ArrayList<String> groupNames = new ArrayList<>(Arrays.asList("线路选择", "画面比例", "播放解码", "超时换源", "偏好设置", "多源切换"));
ArrayList<ArrayList<String>> itemsArrayList = new ArrayList<>();
ArrayList<String> sourceItems = new ArrayList<>();
ArrayList<String> scaleItems = new ArrayList<>(Arrays.asList("默认", "16:9", "4:3", "填充", "原始", "裁剪"));
ArrayList<String> playerDecoderItems = new ArrayList<>(Arrays.asList("系统", "ijk硬解", "ijk软解", "exo"));
ArrayList<String> timeoutItems = new ArrayList<>(Arrays.asList("5s", "10s", "15s", "20s", "25s", "30s"));
ArrayList<String> personalSettingItems = new ArrayList<>(Arrays.asList("显示时间", "显示网速", "换台反转", "跨选分类"));
// ArrayList<String> yumItems = new ArrayList<>(Arrays.asList("线路1", "线路2", "线路3"));
ArrayList<String> yumItems = new ArrayList<>();
try {
JsonArray jsonArray = Hawk.get(HawkConfig.LIVE_GROUP_LIST,new JsonArray());
for (int i=0; i< jsonArray.size();i++) {
JsonObject jsonObject = jsonArray.get(i).getAsJsonObject();
String name = jsonObject.has("name")?jsonObject.get("name").getAsString():"线路"+(i+1);
yumItems.add(name);
}
} catch (Exception e) {
// 捕获任何可能发生的异常
e.printStackTrace();
}
itemsArrayList.add(sourceItems);
itemsArrayList.add(scaleItems);
itemsArrayList.add(playerDecoderItems);
itemsArrayList.add(timeoutItems);
itemsArrayList.add(personalSettingItems);
itemsArrayList.add(yumItems);
liveSettingGroupList.clear();
for (int i = 0; i < groupNames.size(); i++) {
@ -1648,6 +1694,7 @@ public class LivePlayActivity extends BaseActivity {
liveSettingGroupList.get(4).getLiveSettingItems().get(1).setItemSelected(Hawk.get(HawkConfig.LIVE_SHOW_NET_SPEED, false));
liveSettingGroupList.get(4).getLiveSettingItems().get(2).setItemSelected(Hawk.get(HawkConfig.LIVE_CHANNEL_REVERSE, false));
liveSettingGroupList.get(4).getLiveSettingItems().get(3).setItemSelected(Hawk.get(HawkConfig.LIVE_CROSS_GROUP, false));
liveSettingGroupList.get(5).getLiveSettingItems().get(Hawk.get(HawkConfig.LIVE_GROUP_INDEX, 0)).setItemSelected(true);
}
private void loadCurrentSourceList() {

@ -688,9 +688,10 @@ public class PlayActivity extends BaseActivity {
} catch (Throwable th) {
}
} else {
//获取播放信息错误后只需再重试一次
autoRetryCount=1;
errorWithRetry("获取播放信息错误", true);
setTip("获取播放信息错误", false, true);
// 获取播放信息错误后只需再重试一次
// autoRetryCount=2;
// errorWithRetry("获取播放信息错误", true);
}
}
});
@ -840,7 +841,7 @@ public class PlayActivity extends BaseActivity {
boolean autoRetry() {
long currentTime = System.currentTimeMillis();
// 如果距离上次重试超过 10 秒(10000 毫秒),重置重试次数
if (currentTime - lastRetryTime > 10_000) {
if (autoRetryCount < 2 && currentTime - lastRetryTime > 10_000) {
autoRetryCount = 0;
}
lastRetryTime = currentTime; // 更新上次调用时间

@ -707,9 +707,10 @@ public class PlayFragment extends BaseLazyFragment {
// Toast.makeText(mContext, "获取播放信息错误1", Toast.LENGTH_SHORT).show();
}
} else {
//获取播放信息错误后只需再重试一次
autoRetryCount=1;
errorWithRetry("获取播放信息错误", true);
setTip("获取播放信息错误", false, true);
// 获取播放信息错误后只需再重试一次
// autoRetryCount=2;
// errorWithRetry("获取播放信息错误", true);
}
}
});
@ -871,7 +872,11 @@ public class PlayFragment extends BaseLazyFragment {
private long lastRetryTime = 0; // 记录上次调用时间(毫秒)
boolean autoRetry() {
long currentTime = System.currentTimeMillis();
if (currentTime - lastRetryTime > 10_000)autoRetryCount = 0;
if (autoRetryCount<2 && currentTime - lastRetryTime > 10_000){
LOG.i("echo-reset-autoRetryCount");
autoRetryCount = 0;
}
lastRetryTime = currentTime; // 更新上次调用时间
if (loadFoundVideoUrls != null && loadFoundVideoUrls.size() > 0) {
autoRetryFromLoadFoundVideoUrls();

@ -731,8 +731,8 @@ public class SourceViewModel extends ViewModel {
});
try {
String json = future.get(10, TimeUnit.SECONDS);
LOG.i("echo--getPlay--" + json);
String json = future.get(8, TimeUnit.SECONDS);
LOG.i("echo--getPlay--result:" + json);
// 处理返回的 JSON
if (!TextUtils.isEmpty(json)) {
JSONObject result = new JSONObject(json);

Loading…
Cancel
Save