From 51973e8ff5b3282f97660ddb3c9ce7e79e27f648 Mon Sep 17 00:00:00 2001 From: Bart De Vries Date: Mon, 23 Aug 2021 10:55:31 +0200 Subject: [PATCH] Add logging and apply clang-format --- android/src/org/kde/kasts/KastsActivity.java | 12 ++++++++ src/audiomanager.cpp | 2 +- src/mediasessionclient.cpp | 30 +++++++++++++------- src/mediasessionclient.h | 4 +-- 4 files changed, 34 insertions(+), 14 deletions(-) diff --git a/android/src/org/kde/kasts/KastsActivity.java b/android/src/org/kde/kasts/KastsActivity.java index 1730dc2c..9f67a63f 100755 --- a/android/src/org/kde/kasts/KastsActivity.java +++ b/android/src/org/kde/kasts/KastsActivity.java @@ -94,6 +94,8 @@ public class KastsActivity extends QtActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + Log.d(TAG, "JAVA onCreate of MediaSession called."); + mediaSession = new MediaSessionCompat(this, TAG); mediaSession.setFlags( MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | @@ -111,6 +113,8 @@ public class KastsActivity extends QtActivity public void onDestroy() { super.onDestroy(); + Log.d(TAG, "JAVA onDestroy of MediaSession called."); + mediaSession.release(); } @@ -127,6 +131,8 @@ public class KastsActivity extends QtActivity public void onPlay() { super.onPlay(); + Log.d(TAG, "JAVA onDestroy of onPlay callback called."); + if (!mediaSession.isActive()) { mediaSession.setActive(true); } @@ -136,6 +142,8 @@ public class KastsActivity extends QtActivity public void onPause() { super.onPause(); + Log.d(TAG, "JAVA onDestroy of onPause callback called."); + //JNI to audiomanager pause //setPlaybackState for mediaSession } @@ -144,6 +152,8 @@ public class KastsActivity extends QtActivity public void onStop() { super.onStop(); + Log.d(TAG, "JAVA onDestroy of onStop callback called."); + //JNI call to audiomanager stop mediaSession.setActive(false); } @@ -152,6 +162,8 @@ public class KastsActivity extends QtActivity public void onSkipToNext() { super.onPause(); + Log.d(TAG, "JAVA onDestroy of onSkipToNext callback called."); + //JNI to audiomanager next } } diff --git a/src/audiomanager.cpp b/src/audiomanager.cpp index d2cf0e2e..49fca9e9 100644 --- a/src/audiomanager.cpp +++ b/src/audiomanager.cpp @@ -18,10 +18,10 @@ #include "audiologging.h" #include "datamanager.h" #include "feed.h" +#include "mediasessionclient.h" #include "models/errorlogmodel.h" #include "powermanagementinterface.h" #include "settingsmanager.h" -#include "mediasessionclient.h" class AudioManagerPrivate { diff --git a/src/mediasessionclient.cpp b/src/mediasessionclient.cpp index ff5c1eb7..8a0e64e7 100644 --- a/src/mediasessionclient.cpp +++ b/src/mediasessionclient.cpp @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021 Swapnil Tripathi * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL -*/ + */ #include "mediasessionclient.h" #include "audiomanager.h" @@ -9,8 +9,8 @@ #include #ifdef Q_OS_ANDROID -#include #include +#include static void play(JNIEnv *env, jobject thiz) { @@ -40,10 +40,10 @@ static void seek(JNIEnv *env, jobject thiz, jlong position) Q_UNUSED(position) qWarning() << "JAVA seek() working."; } -static const JNINativeMethod methods[] {{"playerPlay", "()V", reinterpret_cast(play)}, - {"playerPause", "()V", reinterpret_cast(pause)}, - {"playerNext", "()V", reinterpret_cast(next)}, - {"playerSeek", "(J)V", reinterpret_cast(seek)}}; +static const JNINativeMethod methods[]{{"playerPlay", "()V", reinterpret_cast(play)}, + {"playerPause", "()V", reinterpret_cast(pause)}, + {"playerNext", "()V", reinterpret_cast(next)}, + {"playerSeek", "(J)V", reinterpret_cast(seek)}}; Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { @@ -66,7 +66,7 @@ Q_DECL_EXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) } #endif -MediaSessionClient* MediaSessionClient::s_instance = nullptr; +MediaSessionClient *MediaSessionClient::s_instance = nullptr; MediaSessionClient::MediaSessionClient(AudioManager *audioPlayer, QObject *parent) : QObject(parent) @@ -97,7 +97,7 @@ MediaSessionClient::MediaSessionClient(AudioManager *audioPlayer, QObject *paren // Connect android notification's play action to skip to next media. } -MediaSessionClient* MediaSessionClient::instance() +MediaSessionClient *MediaSessionClient::instance() { return s_instance; } @@ -106,7 +106,7 @@ void MediaSessionClient::setSessionPlaybackState() { qWarning() << "MediaSessionClient::setSessionPlaybackState called with state value = " << m_audioPlayer->playbackState(); int status = -1; - switch(m_audioPlayer->playbackState()) { + switch (m_audioPlayer->playbackState()) { case QMediaPlayer::PlayingState: status = 0; break; @@ -135,7 +135,7 @@ void MediaSessionClient::setSessionMetadata() if (entry->authors().count() > 0) { for (auto &author : entry->authors()) { authorString.append(author->name()); - if(entry->authors().count() > 1) + if (entry->authors().count() > 1) authorString.append(QStringLiteral(", ")); } } @@ -153,7 +153,15 @@ void MediaSessionClient::setSessionMetadata() int rate = m_audioPlayer->playbackRate(); // Playback rate - QAndroidJniObject::callStaticMethod("org/kde/kasts/KastsActivity", "setMetadata","(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJF)V",title.object(), author.object(), album.object(), (jlong)position, (jlong)duration, (jfloat)rate); + QAndroidJniObject::callStaticMethod("org/kde/kasts/KastsActivity", + "setMetadata", + "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JJF)V", + title.object(), + author.object(), + album.object(), + (jlong)position, + (jlong)duration, + (jfloat)rate); #endif } diff --git a/src/mediasessionclient.h b/src/mediasessionclient.h index a31d582f..e4a1260d 100644 --- a/src/mediasessionclient.h +++ b/src/mediasessionclient.h @@ -1,7 +1,7 @@ /* * SPDX-FileCopyrightText: 2021 Swapnil Tripathi * SPDX-License-Identifier: LicenseRef-KDE-Accepted-LGPL -*/ + */ #pragma once @@ -19,7 +19,7 @@ class MediaSessionClient : public QObject Q_OBJECT public: explicit MediaSessionClient(AudioManager *audioPlayer, QObject *parent = nullptr); - static MediaSessionClient* instance(); + static MediaSessionClient *instance(); Q_SIGNALS: void play();