mirror of
https://github.com/ArcaneChat/android.git
synced 2026-06-02 03:33:42 +02:00
Address code review feedback: fix sentinel value, preserve audio title, simplify JS checks
Agent-Logs-Url: https://github.com/ArcaneChat/android/sessions/57af82f8-b482-4d5a-977f-fc74ffd48db3 Co-authored-by: adbenitez <24558636+adbenitez@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6ecb276a49
commit
3f442377e7
@@ -92,6 +92,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
private TextToSpeech tts;
|
||||
|
||||
private boolean isAudioPlaying = false;
|
||||
private String currentAudioTitle = "";
|
||||
private @Nullable MediaController webxdcMediaController;
|
||||
private @Nullable ListenableFuture<MediaController> webxdcMediaControllerFuture;
|
||||
private @Nullable BroadcastReceiver notificationControlReceiver;
|
||||
@@ -824,6 +825,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
() -> {
|
||||
if (webxdcMediaController == null) return;
|
||||
isAudioPlaying = true;
|
||||
currentAudioTitle = title;
|
||||
Bundle args = new Bundle();
|
||||
args.putString("title", title);
|
||||
args.putString(
|
||||
@@ -846,6 +848,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
() -> {
|
||||
if (webxdcMediaController == null) return;
|
||||
isAudioPlaying = false;
|
||||
currentAudioTitle = "";
|
||||
webxdcMediaController.sendCustomCommand(
|
||||
new SessionCommand(WebxdcMediaSessionService.COMMAND_AUDIO_STOPPED, new Bundle()),
|
||||
Bundle.EMPTY);
|
||||
@@ -877,7 +880,7 @@ public class WebxdcActivity extends WebViewActivity implements DcEventCenter.DcE
|
||||
if (webxdcMediaController == null) return;
|
||||
isAudioPlaying = true;
|
||||
Bundle args = new Bundle();
|
||||
args.putString("title", "");
|
||||
args.putString("title", currentAudioTitle);
|
||||
args.putString(
|
||||
"artist",
|
||||
WebxdcActivity.this.dcAppMsg.getWebxdcInfo().optString("name", ""));
|
||||
|
||||
@@ -268,13 +268,12 @@ public class WebxdcMediaSessionService extends MediaSessionService {
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private void handleAudioStarted(Bundle args) {
|
||||
if (args == null) args = Bundle.EMPTY;
|
||||
String title = args.getString("title", "");
|
||||
String artist = args.getString("artist", "");
|
||||
int msgId = args.getInt("msg_id", 0);
|
||||
int accountId = args.getInt("account_id", 0);
|
||||
|
||||
if (msgId != 0) {
|
||||
if (args.containsKey("msg_id")) {
|
||||
int msgId = args.getInt("msg_id");
|
||||
int accountId = args.getInt("account_id", 0);
|
||||
updateSessionActivity(accountId, msgId);
|
||||
}
|
||||
if (stubPlayer != null) {
|
||||
|
||||
@@ -191,19 +191,13 @@ window.webxdc = (() => {
|
||||
if (el._arcaneMediaListened) return;
|
||||
el._arcaneMediaListened = true;
|
||||
el.addEventListener('play', function() {
|
||||
if (typeof InternalJSApi !== 'undefined' && InternalJSApi.notifyAudioStarted) {
|
||||
InternalJSApi.notifyAudioStarted(document.title || '');
|
||||
}
|
||||
if (window.InternalJSApi) InternalJSApi.notifyAudioStarted(document.title || '');
|
||||
});
|
||||
el.addEventListener('pause', function() {
|
||||
if (typeof InternalJSApi !== 'undefined' && InternalJSApi.notifyAudioPaused) {
|
||||
InternalJSApi.notifyAudioPaused();
|
||||
}
|
||||
if (window.InternalJSApi) InternalJSApi.notifyAudioPaused();
|
||||
});
|
||||
el.addEventListener('ended', function() {
|
||||
if (typeof InternalJSApi !== 'undefined' && InternalJSApi.notifyAudioStopped) {
|
||||
InternalJSApi.notifyAudioStopped();
|
||||
}
|
||||
if (window.InternalJSApi) InternalJSApi.notifyAudioStopped();
|
||||
});
|
||||
})(elements[i]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user