From 48744f636f21beb01a9ad0adadef9b9cf49d09f8 Mon Sep 17 00:00:00 2001 From: Swapnil Tripathi Date: Thu, 5 Aug 2021 05:26:49 +0530 Subject: [PATCH] Added C++ client --- CMakeLists.txt | 8 +++ android/AndroidManifest.xml | 2 +- android/src/org/kde/kasts/MediaService.java | 61 +++++++++++++++++++-- src/CMakeLists.txt | 5 ++ src/audiomanager.cpp | 2 + src/mediasessionclient.cpp | 16 ++++++ src/mediasessionclient.h | 13 +++++ 7 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 src/mediasessionclient.cpp create mode 100644 src/mediasessionclient.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c29e63c2..155b59af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,13 @@ else() find_package(Qt5 ${QT_MIN_VERSION} REQUIRED COMPONENTS Widgets DBus) endif() +if (ANDROID) + find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG QUIET OPTIONAL_COMPONENTS AndroidExtras) + set_package_properties(Qt5AndroidExtras PROPERTIES + DESCRIPTION "Qt5 AndroidExtras is needed to provide the Android integration." + TYPE REQUIRED) +endif() + add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_NO_URL_CAST_FROM_STRING @@ -61,6 +68,7 @@ add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_DISABLE_DEPRECATED_BEFORE=0x050d00 ) + install(PROGRAMS org.kde.kasts.desktop DESTINATION ${KDE_INSTALL_APPDIR}) install(FILES org.kde.kasts.appdata.xml DESTINATION ${KDE_INSTALL_METAINFODIR}) install(FILES kasts.svg DESTINATION ${KDE_INSTALL_FULL_ICONDIR}/hicolor/scalable/apps) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index ffad021d..4dde538f 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -7,7 +7,7 @@ diff --git a/android/src/org/kde/kasts/MediaService.java b/android/src/org/kde/kasts/MediaService.java index fb14a8cc..840c6005 100644 --- a/android/src/org/kde/kasts/MediaService.java +++ b/android/src/org/kde/kasts/MediaService.java @@ -8,22 +8,75 @@ package org.kde.kasts; import android.app.Service; +import android.content.Context; import android.content.Intent; import android.os.IBinder; import android.os.Bundle; import android.support.v4.media.session.MediaSessionCompat; +import android.support.v4.media.session.PlaybackStateCompat; +import android.util.Log; public class MediaService extends Service { public static final String TAG = "MediaService"; - private MediaSessionCompat mSession; - @Override - public IBinder onBind(Intent intent) { - return null; + + private class MediaSessionCallback extends MediaSessionCompat.Callback { + private Context mContext; + + public MediaSessionCallback(Context context) { + super(); + + mContext = context; + } + + @Override + public void onPlay() { + super.onPlay(); + + mSession.setActive(true); + + //JNI to audiomanager play + //setPlaybackState for mSession + } + + @Override + public void onPause() { + super.onPause(); + + //JNI to audiomanager pause + //setPlaybackState for mSession + } + + @Override + public void onStop() { + super.onStop(); + + //JNI call to audiomanager stop + mSession.setActive(false); + } } @Override public void onCreate() { super.onCreate(); + + mSession = new MediaSessionCompat(this, TAG); + mSession.setFlags( + MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | + MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS | + MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS); + mSession.setCallback(new MediaSessionCallback(this)); + } + + @Override + public void onDestroy() { + super.onDestroy(); + + mSession.release(); + } + + @Override + public IBinder onBind(Intent intent) { + return null; } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 199c1107..b948d47d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -140,6 +140,11 @@ if(ANDROID) target_link_libraries(kasts PRIVATE ZLIB::ZLIB) endif() + target_link_libraries(kasts + LINK_PUBLIC + Qt5::AndroidExtras + ) + kirigami_package_breeze_icons(ICONS window-close window-close-symbolic diff --git a/src/audiomanager.cpp b/src/audiomanager.cpp index 4a75d66e..1790c6a2 100644 --- a/src/audiomanager.cpp +++ b/src/audiomanager.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include diff --git a/src/mediasessionclient.cpp b/src/mediasessionclient.cpp new file mode 100644 index 00000000..3cdabbaa --- /dev/null +++ b/src/mediasessionclient.cpp @@ -0,0 +1,16 @@ +/** + * SPDX-FileCopyrightText: 2021 Swapnil Tripathi + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +#include "mediasessionclient.h" +#include "audiomanager.h" + +#include + +MediaSessionClient::MediaSessionClient(QObject *parent) + : QObject(parent) +{ + //connections to be added here. +} diff --git a/src/mediasessionclient.h b/src/mediasessionclient.h new file mode 100644 index 00000000..023e7421 --- /dev/null +++ b/src/mediasessionclient.h @@ -0,0 +1,13 @@ +/** + * SPDX-FileCopyrightText: 2021 Swapnil Tripathi + * + * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL + */ + +#pragma once + +class MediaSessionClient +{ +public: + explicit MediaSessionClient(QObject *parent = nullptr); +};