From 86c28576cca47e5a7e23dc9116604880d684665b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= jaakko.keranen@iki.fi
Date: Sun, 11 Oct 2020 13:18:00 +0300
Subject: [PATCH 1/1] Media: Pause other players when a new one starts
src/media.c | 8 +++++++-
src/media.h | 1 +
src/ui/documentwidget.c | 14 ++++++++++++++
3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/media.c b/src/media.c
index c0d6d3de..dcda0664 100644
--- a/src/media.c
+++ b/src/media.c
@@ -24,6 +24,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
#include "gmdocument.h"
#include "ui/window.h"
#include "audio/player.h"
+#include "app.h"
#include <the_Foundation/ptrarray.h>
#include <stb_image.h>
@@ -214,8 +215,9 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc
updateSourceData_Player(audio->player, NULL, NULL, complete_PlayerUpdate);
}
pushBack_PtrArray(&d->audio, audio);
/* TEST: Start playing right away. */
/* Start playing right away. */
start_Player(audio->player);
postCommandf_App("media.player.started player:%p", audio->player);
}
}
}
@@ -231,6 +233,10 @@ iMediaId findLinkImage_Media(const iMedia *d, iGmLinkId linkId) {
return 0;
}
+size_t numAudio_Media(const iMedia *d) {
+}
iMediaId findLinkAudio_Media(const iMedia *d, iGmLinkId linkId) {
/* TODO: use a hash */
iConstForEach(PtrArray, i, &d->audio) {
diff --git a/src/media.h b/src/media.h
index c19ad8ae..9db6659d 100644
--- a/src/media.h
+++ b/src/media.h
@@ -60,6 +60,7 @@ iMediaId findLinkImage_Media (const iMedia *, uint16_t linkId);
iBool imageInfo_Media (const iMedia *, iMediaId imageId, iGmImageInfo *info_out);
SDL_Texture * imageTexture_Media (const iMedia *, iMediaId imageId);
+size_t numAudio_Media (const iMedia *);
iMediaId findLinkAudio_Media (const iMedia *, uint16_t linkId);
iBool audioInfo_Media (const iMedia *, iMediaId audioId, iGmAudioInfo *info_out);
iPlayer * audioPlayer_Media (const iMedia *, iMediaId audioId);
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index b977e4d9..573cd3e3 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -1421,6 +1421,18 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd)
else if (equal_Command(cmd, "media.updated") || equal_Command(cmd, "media.finished")) {
return handleMediaCommand_DocumentWidget_(d, cmd);
}
/* When one media player starts, pause the others that may be playing. */
const iPlayer *startedPlr = pointerLabel_Command(cmd, "player");
const iMedia * media = media_GmDocument(d->doc);
const size_t num = numAudio_Media(media);
for (size_t id = 1; id <= num; id++) {
iPlayer *plr = audioPlayer_Media(media, id);
if (plr != startedPlr) {
setPaused_Player(plr, iTrue);
}
}
else if (equal_Command(cmd, "document.stop") && document_App() == d) {
if (d->request) {
postCommandf_App(
@@ -2064,6 +2076,8 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
if (!isFinished_GmRequest(req->req)) {
cancel_GmRequest(req->req);
removeMediaRequest_DocumentWidget_(d, linkId);
/* Note: Some of the audio IDs have changed now, layout must
be redone. */
}
}
redoLayout_GmDocument(d->doc);
--
2.25.1
text/plain
This content has been proxied by September (ba2dc).