Fix track bug, limit speed for exo tunneling mode, Update LiveParser.java

pull/458/head
okjack 2 years ago
parent 9bd9166907
commit 207e344b36
  1. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/CastActivity.java
  2. 6
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  3. 5
      app/src/leanback/res/layout/activity_video.xml
  4. 15
      app/src/main/java/com/fongmi/android/tv/api/LiveParser.java
  5. 4
      app/src/main/java/com/fongmi/android/tv/bean/Track.java
  6. 2
      app/src/main/java/com/fongmi/android/tv/player/ExoUtil.java
  7. 10
      app/src/main/java/com/fongmi/android/tv/player/Players.java
  8. 6
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  9. 9
      app/src/mobile/java/com/fongmi/android/tv/ui/dialog/ControlDialog.java
  10. 5
      app/src/mobile/res/layout-sw600dp/activity_video.xml
  11. 5
      app/src/mobile/res/layout/activity_video.xml
  12. 25
      catvod/src/main/java/com/github/catvod/net/OkDns.java
  13. 2
      catvod/src/main/java/com/github/catvod/net/OkHttp.java
  14. 8
      youtube/src/main/java/com/github/kiulian/downloader/YoutubeDownloader.java

@ -474,7 +474,7 @@ public class CastActivity extends BaseActivity implements CustomKeyDownCast.List
@Override
public void onSpeedUp() {
if (!mPlayers.isPlaying()) return;
if (!mPlayers.isPlaying() || !mPlayers.canAdjustSpeed()) return;
mBinding.control.speed.setText(mPlayers.setSpeed(mPlayers.getSpeed() < 3 ? 3 : 5));
mBinding.widget.speed.startAnimation(ResUtil.getAnim(R.anim.forward));
mBinding.widget.speed.setVisibility(View.VISIBLE);

@ -495,8 +495,10 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
private void setPlayerView() {
getIjk().setPlayer(mPlayers.getPlayer());
mBinding.control.player.setText(mPlayers.getPlayerText());
mBinding.control.speed.setEnabled(mPlayers.canAdjustSpeed());
getExo().setVisibility(mPlayers.isExo() ? View.VISIBLE : View.GONE);
getIjk().setVisibility(mPlayers.isIjk() ? View.VISIBLE : View.GONE);
mBinding.control.speed.setText(mPlayers.setSpeed(mHistory.getSpeed()));
}
private void setDecodeView() {
@ -1225,7 +1227,6 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
if (Setting.isIncognito() && mHistory.getKey().equals(getHistoryKey())) mHistory.delete();
mBinding.control.opening.setText(mHistory.getOpening() == 0 ? getString(R.string.play_op) : mPlayers.stringToTime(mHistory.getOpening()));
mBinding.control.ending.setText(mHistory.getEnding() == 0 ? getString(R.string.play_ed) : mPlayers.stringToTime(mHistory.getEnding()));
mBinding.control.speed.setText(mPlayers.setSpeed(mHistory.getSpeed()));
mPlayers.setPlayer(getPlayer());
setScale(getScale());
setPlayerView();
@ -1406,6 +1407,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
}
private void onError(ErrorEvent event) {
Track.delete(getHistoryKey());
showError(event.getMsg());
mClock.setCallback(null);
mPlayers.stop();
@ -1672,7 +1674,7 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
@Override
public void onSpeedUp() {
if (!mPlayers.isPlaying()) return;
if (!mPlayers.isPlaying() || !mPlayers.canAdjustSpeed()) return;
mBinding.control.speed.setText(mPlayers.setSpeed(mPlayers.getSpeed() < 3 ? 3 : 5));
mBinding.widget.speed.startAnimation(ResUtil.getAnim(R.anim.forward));
mBinding.widget.speed.setVisibility(View.VISIBLE);

@ -42,9 +42,8 @@
<tv.danmaku.ijk.media.player.ui.IjkVideoView
android:id="@+id/ijk"
style="@style/Player.Vod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<master.flame.danmaku.ui.widget.DanmakuView

@ -38,9 +38,9 @@ public class LiveParser {
public static void start(Live live) {
if (live.getGroups().size() > 0) return;
if (live.getType() == 0) text(live, getText(live.getUrl(), live.getHeaders()));
if (live.getType() == 1) json(live, getText(live.getUrl(), live.getHeaders()));
if (live.getType() == 2) proxy(live, getText(live.getUrl(), live.getHeaders()));
if (live.getType() == 0) text(live, getText(live));
if (live.getType() == 1) json(live, getText(live));
if (live.getType() == 2) proxy(live, getText(live));
}
public static void text(Live live, String text) {
@ -69,7 +69,6 @@ public class LiveParser {
Setting setting = Setting.create();
Catchup catchup = Catchup.create();
Channel channel = Channel.create("");
text = text.replace("\r\n", "\n");
for (String line : text.split("\n")) {
if (Thread.interrupted()) break;
if (setting.find(line)) {
@ -93,10 +92,10 @@ public class LiveParser {
private static void txt(Live live, String text) {
Setting setting = Setting.create();
text = text.replace("\r\n", "\n");
for (String line : text.split("\n")) {
if (Thread.interrupted()) break;
String[] split = line.split(",");
int index = line.indexOf(",") + 1;
if (setting.find(line)) setting.check(line);
if (line.contains("#genre#")) setting.clear();
if (line.contains("#genre#")) live.getGroups().add(Group.create(split[0], live.isPass()));
@ -104,7 +103,7 @@ public class LiveParser {
if (split.length > 1 && split[1].contains("://")) {
Group group = live.getGroups().get(live.getGroups().size() - 1);
Channel channel = group.find(Channel.create(split[0]));
channel.addUrls(line.substring(line.indexOf(",") + 1).split("#"));
channel.addUrls(line.substring(index).split("#"));
setting.copy(channel);
}
}
@ -122,6 +121,10 @@ public class LiveParser {
}
}
private static String getText(Live live) {
return getText(live.getUrl(), live.getHeaders()).replace("\r\n", "\n");
}
private static String getText(String url, Map<String, String> header) {
if (url.startsWith("file")) return Path.read(url);
if (url.startsWith("http")) return OkHttp.string(url, header);

@ -121,4 +121,8 @@ public class Track {
public static List<Track> find(String key) {
return AppDatabase.get().getTrackDao().find(key);
}
public static void delete(String key) {
AppDatabase.get().getTrackDao().delete(key);
}
}

@ -77,7 +77,7 @@ public class ExoUtil {
}
public static RenderersFactory buildRenderersFactory() {
return new DefaultRenderersFactory(App.get()).setEnableDecoderFallback(true).setExtensionRendererMode(Math.abs(Setting.getDecode(Players.EXO) - 2));
return new DefaultRenderersFactory(App.get()).setEnableDecoderFallback(true).setExtensionRendererMode(Players.isSoft(Players.EXO) ? DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER : DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
}
public static CaptionStyleCompat getCaptionStyle() {

@ -95,6 +95,10 @@ public class Players implements Player.Listener, IMediaPlayer.Listener, Analytic
return Setting.getDecode(player) == HARD;
}
public static boolean isSoft(int player) {
return Setting.getDecode(player) == SOFT;
}
public boolean isExo() {
return player == EXO;
}
@ -251,6 +255,10 @@ public class Players implements Player.Listener, IMediaPlayer.Listener, Analytic
return danmuView != null && danmuView.isPrepared();
}
public boolean canAdjustSpeed() {
return isIjk() || (isExo() && !Setting.isTunnel());
}
public boolean haveTrack(int type) {
if (isExo() && exoPlayer != null) return ExoUtil.haveTrack(exoPlayer.getCurrentTracks(), type);
if (isIjk() && ijkPlayer != null) return ijkPlayer.haveTrack(type);
@ -300,7 +308,7 @@ public class Players implements Player.Listener, IMediaPlayer.Listener, Analytic
}
public String setSpeed(float speed) {
if (exoPlayer != null) exoPlayer.setPlaybackSpeed(this.speed = speed);
if (exoPlayer != null && !Setting.isTunnel()) exoPlayer.setPlaybackSpeed(this.speed = speed);
if (ijkPlayer != null) ijkPlayer.setSpeed(this.speed = speed);
return getSpeedText();
}

@ -398,8 +398,10 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
private void setPlayerView() {
getIjk().setPlayer(mPlayers.getPlayer());
mBinding.control.action.player.setText(mPlayers.getPlayerText());
mBinding.control.action.speed.setEnabled(mPlayers.canAdjustSpeed());
getExo().setVisibility(mPlayers.isExo() ? View.VISIBLE : View.GONE);
getIjk().setVisibility(mPlayers.isIjk() ? View.VISIBLE : View.GONE);
mBinding.control.action.speed.setText(mPlayers.setSpeed(mHistory.getSpeed()));
if (mControlDialog != null && mControlDialog.isVisible()) mControlDialog.updatePlayer();
}
@ -1129,7 +1131,6 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
if (Setting.isIncognito() && mHistory.getKey().equals(getHistoryKey())) mHistory.delete();
mBinding.control.action.opening.setText(mHistory.getOpening() == 0 ? getString(R.string.play_op) : mPlayers.stringToTime(mHistory.getOpening()));
mBinding.control.action.ending.setText(mHistory.getEnding() == 0 ? getString(R.string.play_ed) : mPlayers.stringToTime(mHistory.getEnding()));
mBinding.control.action.speed.setText(mPlayers.setSpeed(mHistory.getSpeed()));
mPlayers.setPlayer(getPlayer());
setScale(getScale());
setPlayerView();
@ -1353,6 +1354,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
private void onError(ErrorEvent event) {
mBinding.swipeLayout.setEnabled(true);
Track.delete(getHistoryKey());
showError(event.getMsg());
mClock.setCallback(null);
mPlayers.stop();
@ -1599,7 +1601,7 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
@Override
public void onSpeedUp() {
if (!mPlayers.isPlaying()) return;
if (!mPlayers.isPlaying() || !mPlayers.canAdjustSpeed()) return;
mBinding.control.action.speed.setText(mPlayers.setSpeed(mPlayers.getSpeed() < 3 ? 3 : 5));
mBinding.widget.speed.startAnimation(ResUtil.getAnim(R.anim.forward));
mBinding.widget.speed.setVisibility(View.VISIBLE);

@ -89,7 +89,6 @@ public class ControlDialog extends BaseDialog implements ParseAdapter.OnClickLis
protected void initView() {
if (player == null) dismiss();
if (player == null) return;
binding.speed.setValue(Math.max(player.getSpeed(), 0.2f));
binding.player.setText(parent.control.action.player.getText());
binding.decode.setText(parent.control.action.decode.getText());
binding.ending.setText(parent.control.action.ending.getText());
@ -102,6 +101,7 @@ public class ControlDialog extends BaseDialog implements ParseAdapter.OnClickLis
binding.dpminiprogress.setActivated(Setting.isDisplayMiniProgress());
setTrackVisible();
setScaleText();
setPlayer();
setParse();
}
@ -219,6 +219,13 @@ public class ControlDialog extends BaseDialog implements ParseAdapter.OnClickLis
binding.decode.setText(parent.control.action.decode.getText());
}
public void setPlayer() {
binding.speed.setEnabled(player.canAdjustSpeed());
binding.speed.setValue(Math.max(player.getSpeed(), 0.5f));
binding.player.setText(parent.control.action.player.getText());
binding.decode.setVisibility(parent.control.action.decode.getVisibility());
}
public void setParseVisible(boolean visible) {
binding.parse.setVisibility(visible ? View.VISIBLE : View.GONE);
binding.parseText.setVisibility(visible ? View.VISIBLE : View.GONE);

@ -40,9 +40,8 @@
<tv.danmaku.ijk.media.player.ui.IjkVideoView
android:id="@+id/ijk"
style="@style/Player.Vod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<master.flame.danmaku.ui.widget.DanmakuView

@ -33,9 +33,8 @@
<tv.danmaku.ijk.media.player.ui.IjkVideoView
android:id="@+id/ijk"
style="@style/Player.Vod"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<master.flame.danmaku.ui.widget.DanmakuView

@ -1,25 +0,0 @@
package com.github.catvod.net;
import androidx.annotation.NonNull;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Dns;
public class OkDns implements Dns {
@NonNull
@Override
public List<InetAddress> lookup(@NonNull String hostname) throws UnknownHostException {
List<InetAddress> items = new ArrayList<>();
for (InetAddress address : InetAddress.getAllByName(hostname)) {
if (address instanceof Inet4Address) items.add(0, address);
else items.add(address);
}
return items;
}
}

@ -49,7 +49,7 @@ public class OkHttp {
}
public static Dns dns() {
return get().dns != null ? get().dns : new OkDns();
return get().dns != null ? get().dns : Dns.SYSTEM;
}
public void setDoh(Doh doh) {

@ -14,8 +14,6 @@ import okhttp3.OkHttpClient;
public class YoutubeDownloader {
private final Downloader downloader;
private final Config config;
private final Parser parser;
public YoutubeDownloader(OkHttpClient client) {
@ -23,14 +21,10 @@ public class YoutubeDownloader {
}
public YoutubeDownloader(Config config, OkHttpClient client) {
this.downloader = new DownloaderImpl(this.config = config, client);
Downloader downloader = new DownloaderImpl(config, client);
this.parser = new ParserImpl(config, downloader, new ExtractorImpl(downloader), new CachedCipherFactory(downloader));
}
public Config getConfig() {
return config;
}
public Response<VideoInfo> getVideoInfo(RequestVideoInfo request) {
return parser.parseVideo(request);
}

Loading…
Cancel
Save