Optimize tvbus

pull/123/head
FongMi 3 years ago
parent b033b18996
commit 94a53c06ce
  1. 2
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/LiveActivity.java
  2. 2
      app/src/main/java/com/fongmi/android/tv/model/LiveViewModel.java
  3. 21
      app/src/main/java/com/fongmi/android/tv/player/source/TVBus.java
  4. 12
      tvbus/src/main/AndroidManifest.xml
  5. 2
      tvbus/src/main/java/com/tvbus/engine/Listener.java
  6. 98
      tvbus/src/main/java/com/tvbus/engine/TVCore.java
  7. 51
      tvbus/src/main/java/com/tvbus/engine/TVService.java

@ -702,7 +702,7 @@ public class LiveActivity extends BaseActivity implements GroupPresenter.OnClick
mPlayers.release();
Force.get().stop();
ZLive.get().stop();
TVBus.get().stop();
TVBus.get().quit();
App.removeCallbacks(mR1, mR2, mR3, mR4, mR5, mR6);
}
}

@ -26,7 +26,6 @@ public class LiveViewModel extends ViewModel {
public void getLive(Live home) {
execute(() -> {
TVBus.get().init(home.getCore());
LiveParser.start(home);
return home;
});
@ -34,6 +33,7 @@ public class LiveViewModel extends ViewModel {
public void getUrl(Channel item) {
execute(() -> {
TVBus.get().stop();
String url = item.getUrls().get(item.getLine());
if (item.isForce()) item.setUrl(Force.get().fetch(url));
else if (item.isZLive()) item.setUrl(ZLive.get().fetch(url));

@ -1,14 +1,14 @@
package com.fongmi.android.tv.player.source;
import com.fongmi.android.tv.App;
import com.fongmi.android.tv.api.LiveConfig;
import com.fongmi.android.tv.bean.Core;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.tvbus.engine.Listener;
import com.tvbus.engine.TVCore;
import com.tvbus.engine.TVListener;
import com.tvbus.engine.TVService;
public class TVBus implements TVListener {
public class TVBus implements Listener {
private final Gson gson;
private TVCore tvcore;
@ -26,13 +26,16 @@ public class TVBus implements TVListener {
this.gson = new Gson();
}
public void init(Core core) {
private void init(Core core) {
if (core == null) return;
tvcore = TVCore.getInstance().listener(this);
TVService.start(App.get(), core.getAuth(), core.getName(), core.getPass(), core.getBroker());
tvcore = new TVCore().listener(this);
tvcore.auth(core.getAuth()).name(core.getName()).pass(core.getPass()).broker(core.getBroker());
tvcore.serv(0).play(8902).mode(1).init(App.get());
}
public String fetch(String url) throws InterruptedException {
if (tvcore == null) init(LiveConfig.get().getHome().getCore());
if (tvcore == null) return "";
tvcore.start(url);
onWait();
return hls;
@ -51,7 +54,11 @@ public class TVBus implements TVListener {
}
public void stop() {
TVService.stop(App.get());
if (tvcore != null) tvcore.stop();
}
public void quit() {
if (tvcore != null) tvcore.quit();
}
@Override

@ -1,12 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tvbus.engine">
<application>
<service
android:name="com.tvbus.engine.TVService"
android:exported="false" />
</application>
</manifest>
<manifest package="com.tvbus.engine" />

@ -1,6 +1,6 @@
package com.tvbus.engine;
public interface TVListener {
public interface Listener {
void onInited(String result);

@ -5,116 +5,74 @@ import android.text.TextUtils;
public class TVCore {
private long nativeHandle;
private final long handle;
private static class Loader {
static volatile TVCore INSTANCE = new TVCore();
public TVCore() {
PmsHook.inject();
System.loadLibrary("tvcore");
handle = initialise();
}
public static TVCore getInstance() {
return Loader.INSTANCE;
}
private TVCore() {
try {
PmsHook.inject();
System.loadLibrary("tvcore");
nativeHandle = initialise();
} catch (Throwable ignored) {
}
}
public TVCore listener(TVListener listener) {
try {
setListener(nativeHandle, listener);
} catch (Throwable ignored) {
}
public TVCore listener(Listener listener) {
setListener(handle, listener);
return this;
}
public TVCore play(int port) {
try {
setPlayPort(nativeHandle, port);
} catch (Throwable ignored) {
}
setPlayPort(handle, port);
return this;
}
public TVCore serv(int port) {
try {
setServPort(nativeHandle, port);
} catch (Throwable ignored) {
}
setServPort(handle, port);
return this;
}
public TVCore mode(int mode) {
try {
setRunningMode(nativeHandle, mode);
} catch (Throwable ignored) {
}
setRunningMode(handle, mode);
return this;
}
public TVCore auth(String str) {
try {
if (!TextUtils.isEmpty(str)) setAuthUrl(nativeHandle, str);
} catch (Throwable ignored) {
}
if (!TextUtils.isEmpty(str)) setAuthUrl(handle, str);
return this;
}
public TVCore broker(String str) {
try {
if (!TextUtils.isEmpty(str)) setMKBroker(nativeHandle, str);
} catch (Throwable ignored) {
}
if (!TextUtils.isEmpty(str)) setMKBroker(handle, str);
return this;
}
public TVCore name(String str) {
try {
if (!TextUtils.isEmpty(str)) setUsername(nativeHandle, str);
} catch (Throwable ignored) {
}
if (!TextUtils.isEmpty(str)) setUsername(handle, str);
return this;
}
public TVCore pass(String str) {
try {
if (!TextUtils.isEmpty(str)) setPassword(nativeHandle, str);
} catch (Throwable ignored) {
}
if (!TextUtils.isEmpty(str)) setPassword(handle, str);
return this;
}
public void init(Context context) {
new Thread(() -> {
init(handle, context);
run(handle);
}).start();
}
public void start(String url) {
try {
start(nativeHandle, url);
} catch (Throwable ignored) {
}
start(handle, url);
}
public void stop() {
try {
stop(nativeHandle);
} catch (Throwable ignored) {
}
stop(handle);
}
void init(Context context) {
new Thread(() -> {
init(nativeHandle, context);
run(nativeHandle);
}).start();
public void quit() {
quit(handle);
}
void quit() {
try {
quit(nativeHandle);
} catch (Throwable ignored) {
}
}
private native long initialise();
private native int init(long handle, Context context);
@ -140,7 +98,5 @@ public class TVCore {
private native void setUsername(long handle, String str);
private native void setListener(long handle, TVListener listener);
private native long initialise();
private native void setListener(long handle, Listener listener);
}

@ -1,51 +0,0 @@
package com.tvbus.engine;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
public class TVService extends Service {
private TVCore tvcore;
public static void start(Context context, String auth, String name, String pass, String broker) {
try {
Intent intent = new Intent(context, TVService.class);
intent.putExtra("auth", auth);
intent.putExtra("name", name);
intent.putExtra("pass", pass);
intent.putExtra("broker", broker);
context.startService(intent);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void stop(Context context) {
try {
context.stopService(new Intent(context, TVService.class));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
tvcore = TVCore.getInstance().auth(intent.getStringExtra("auth")).name(intent.getStringExtra("name")).pass(intent.getStringExtra("pass")).broker(intent.getStringExtra("broker"));
tvcore.serv(0).play(8902).mode(1).init(this);
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
tvcore.stop();
tvcore.quit();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Loading…
Cancel
Save