Add control api

pull/617/head
FongMi 3 months ago
parent cd889fe9ea
commit 6493bdf483
  1. 4
      app/src/leanback/java/com/fongmi/android/tv/ui/activity/VideoActivity.java
  2. 28
      app/src/main/java/com/fongmi/android/tv/event/ActionEvent.java
  3. 10
      app/src/main/java/com/fongmi/android/tv/impl/SessionCallback.java
  4. 13
      app/src/main/java/com/fongmi/android/tv/server/process/Action.java
  5. 4
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/VideoActivity.java

@ -1048,6 +1048,10 @@ public class VideoActivity extends BaseActivity implements CustomKeyDownVod.List
mBinding.control.next.performClick();
} else if (ActionEvent.PREV.equals(event.getAction())) {
mBinding.control.prev.performClick();
} else if (ActionEvent.LOOP.equals(event.getAction())) {
mBinding.control.loop.performClick();
} else if (ActionEvent.REPLAY.equals(event.getAction())) {
onReset(true);
} else if (ActionEvent.STOP.equals(event.getAction())) {
finish();
}

@ -9,33 +9,51 @@ public class ActionEvent {
public static String STOP = BuildConfig.APPLICATION_ID.concat(".stop");
public static String PREV = BuildConfig.APPLICATION_ID.concat(".prev");
public static String NEXT = BuildConfig.APPLICATION_ID.concat(".next");
public static String LOOP = BuildConfig.APPLICATION_ID.concat(".loop");
public static String PLAY = BuildConfig.APPLICATION_ID.concat(".play");
public static String PAUSE = BuildConfig.APPLICATION_ID.concat(".pause");
public static String AUDIO = BuildConfig.APPLICATION_ID.concat(".audio");
public static String REPLAY = BuildConfig.APPLICATION_ID.concat(".replay");
public static String UPDATE = BuildConfig.APPLICATION_ID.concat(".update");
private final String action;
public static void send(String action) {
private static void send(String action) {
EventBus.getDefault().post(new ActionEvent(action));
}
public static void update() {
send(UPDATE);
public static void stop() {
send(STOP);
}
public static void prev() {
send(PREV);
}
public static void next() {
send(NEXT);
}
public static void prev() {
send(PREV);
public static void loop() {
send(LOOP);
}
public static void play() {
send(PLAY);
}
public static void pause() {
send(PAUSE);
}
public static void replay() {
send(REPLAY);
}
public static void update() {
send(UPDATE);
}
public ActionEvent(String action) {
this.action = action;
}

@ -24,26 +24,26 @@ public class SessionCallback extends MediaSessionCompat.Callback {
@Override
public void onPlay() {
ActionEvent.send(ActionEvent.PLAY);
ActionEvent.play();
}
@Override
public void onPause() {
ActionEvent.send(ActionEvent.PAUSE);
ActionEvent.pause();
}
@Override
public void onSkipToPrevious() {
ActionEvent.send(ActionEvent.PREV);
ActionEvent.prev();
}
@Override
public void onSkipToNext() {
ActionEvent.send(ActionEvent.NEXT);
ActionEvent.next();
}
@Override
public void onStop() {
ActionEvent.send(ActionEvent.STOP);
ActionEvent.stop();
}
}

@ -9,6 +9,7 @@ import com.fongmi.android.tv.bean.Config;
import com.fongmi.android.tv.bean.Device;
import com.fongmi.android.tv.bean.History;
import com.fongmi.android.tv.bean.Keep;
import com.fongmi.android.tv.event.ActionEvent;
import com.fongmi.android.tv.event.CastEvent;
import com.fongmi.android.tv.event.RefreshEvent;
import com.fongmi.android.tv.event.ServerEvent;
@ -46,6 +47,7 @@ public class Action implements Process {
else if ("search".equals(param)) onSearch(params);
else if ("setting".equals(param)) onSetting(params);
else if ("refresh".equals(param)) onRefresh(params);
else if ("control".equals(param)) onControl(params);
return Nano.ok();
}
@ -86,6 +88,17 @@ public class Action implements Process {
else if ("subtitle".equals(type)) RefreshEvent.subtitle(path);
}
private void onControl(Map<String, String> params) {
String type = params.get("type");
if ("stop".equals(type)) ActionEvent.stop();
else if ("prev".equals(type)) ActionEvent.prev();
else if ("next".equals(type)) ActionEvent.next();
else if ("loop".equals(type)) ActionEvent.loop();
else if ("play".equals(type)) ActionEvent.play();
else if ("pause".equals(type)) ActionEvent.pause();
else if ("replay".equals(type)) ActionEvent.replay();
}
private void onCast(Map<String, String> params) {
Config config = Config.objectFrom(params.get("config"));
Device device = Device.objectFrom(params.get("device"));

@ -1149,6 +1149,10 @@ public class VideoActivity extends BaseActivity implements Clock.Callback, Custo
mBinding.control.next.performClick();
} else if (ActionEvent.PREV.equals(event.getAction())) {
mBinding.control.prev.performClick();
} else if (ActionEvent.LOOP.equals(event.getAction())) {
mBinding.control.action.loop.performClick();
} else if (ActionEvent.REPLAY.equals(event.getAction())) {
onReset(true);
} else if (ActionEvent.AUDIO.equals(event.getAction())) {
moveTaskToBack(true);
setAudioOnly(true);

Loading…
Cancel
Save