From 054a8f3b1f692d14687ce14fa8d143edc8f988f0 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Wed, 6 Feb 2019 15:35:04 +0100 Subject: Android: Implement audio roles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduced custom and standard audio role controls using MediaPlayer.setAudioAttributes(AudioAttributes) which added in API level 21. Custom audio roles might contain a list of roles separated by comma. E.g "CONTENT_TYPE_MOVIE,USAGE_ALARM", which means content type is movie and usage is alarm. [ChangeLog][Platform Specific Changes][Android] Implemented audio roles. Task-number: QTBUG-73119 Change-Id: I281d1ce899d29f54d271516a1fca5f11c897fc90 Reviewed-by: Christian Strømme --- .../android/multimedia/QtAndroidMediaPlayer.java | 25 ++++++ .../android/src/mediaplayer/mediaplayer.pri | 4 + .../src/mediaplayer/qandroidaudiorolecontrol.cpp | 77 +++++++++++++++++++ .../src/mediaplayer/qandroidaudiorolecontrol.h | 63 +++++++++++++++ .../mediaplayer/qandroidcustomaudiorolecontrol.cpp | 87 +++++++++++++++++++++ .../mediaplayer/qandroidcustomaudiorolecontrol.h | 63 +++++++++++++++ .../src/mediaplayer/qandroidmediaplayercontrol.cpp | 10 +++ .../src/mediaplayer/qandroidmediaplayercontrol.h | 2 + .../src/mediaplayer/qandroidmediaservice.cpp | 18 +++++ .../android/src/mediaplayer/qandroidmediaservice.h | 4 + .../src/wrappers/jni/androidmediaplayer.cpp | 89 ++++++++++++++++++++++ .../android/src/wrappers/jni/androidmediaplayer.h | 3 + 12 files changed, 445 insertions(+) create mode 100644 src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp create mode 100644 src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h create mode 100644 src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp create mode 100644 src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h (limited to 'src/plugins') diff --git a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java index 647cc7fe0..6569a7b8d 100644 --- a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java +++ b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java @@ -46,6 +46,7 @@ import java.io.FileInputStream; // API is level is < 9 unless marked otherwise. import android.content.Context; import android.media.MediaPlayer; +import android.media.AudioAttributes; import android.net.Uri; import android.util.Log; import java.io.FileDescriptor; @@ -65,6 +66,7 @@ public class QtAndroidMediaPlayer native public void onStateChangedNative(int state, long id); private MediaPlayer mMediaPlayer = null; + private AudioAttributes mAudioAttributes = null; private Uri mUri = null; private final long mID; private final Context mContext; @@ -235,6 +237,7 @@ public class QtAndroidMediaPlayer setState(State.Idle); // Make sure the new media player has the volume that was set on the QMediaPlayer setVolumeHelper(mMuted ? 0 : mVolume); + setAudioAttributes(mMediaPlayer, mAudioAttributes); } } @@ -547,4 +550,26 @@ public class QtAndroidMediaPlayer setState(State.Uninitialized); } + + public void setAudioAttributes(int type, int usage) + { + mAudioAttributes = new AudioAttributes.Builder() + .setUsage(usage) + .setContentType(type) + .build(); + + setAudioAttributes(mMediaPlayer, mAudioAttributes); + } + + static private void setAudioAttributes(MediaPlayer player, AudioAttributes attr) + { + if (player == null || attr == null) + return; + + try { + player.setAudioAttributes(attr); + } catch (final IllegalArgumentException e) { + Log.d(TAG, "" + e.getMessage()); + } + } } diff --git a/src/plugins/android/src/mediaplayer/mediaplayer.pri b/src/plugins/android/src/mediaplayer/mediaplayer.pri index 9f758a993..3a9cef3a1 100644 --- a/src/plugins/android/src/mediaplayer/mediaplayer.pri +++ b/src/plugins/android/src/mediaplayer/mediaplayer.pri @@ -4,10 +4,14 @@ HEADERS += \ $$PWD/qandroidmediaplayercontrol.h \ $$PWD/qandroidmediaservice.h \ $$PWD/qandroidmetadatareadercontrol.h \ + $$PWD/qandroidaudiorolecontrol.h \ + $$PWD/qandroidcustomaudiorolecontrol.h \ $$PWD/qandroidmediaplayervideorenderercontrol.h SOURCES += \ $$PWD/qandroidmediaplayercontrol.cpp \ $$PWD/qandroidmediaservice.cpp \ $$PWD/qandroidmetadatareadercontrol.cpp \ + $$PWD/qandroidaudiorolecontrol.cpp \ + $$PWD/qandroidcustomaudiorolecontrol.cpp \ $$PWD/qandroidmediaplayervideorenderercontrol.cpp diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp new file mode 100644 index 000000000..5879b0cb9 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.cpp @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidaudiorolecontrol.h" + +QT_BEGIN_NAMESPACE + +QAndroidAudioRoleControl::QAndroidAudioRoleControl(QObject *parent) + : QAudioRoleControl(parent) +{ +} + +QAudio::Role QAndroidAudioRoleControl::audioRole() const +{ + return m_role; +} + +void QAndroidAudioRoleControl::setAudioRole(QAudio::Role role) +{ + if (m_role == role) + return; + + m_role = role; + emit audioRoleChanged(m_role); +} + +QList QAndroidAudioRoleControl::supportedAudioRoles() const +{ + return QList() + << QAudio::VoiceCommunicationRole + << QAudio::MusicRole + << QAudio::VideoRole + << QAudio::SonificationRole + << QAudio::AlarmRole + << QAudio::NotificationRole + << QAudio::RingtoneRole + << QAudio::AccessibilityRole + << QAudio::GameRole; +} + +QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h new file mode 100644 index 000000000..89219e026 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidaudiorolecontrol.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDAUDIOROLECONTROL_H +#define QANDROIDAUDIOROLECONTROL_H + +#include + +QT_BEGIN_NAMESPACE + +class QAndroidAudioRoleControl : public QAudioRoleControl +{ + Q_OBJECT +public: + explicit QAndroidAudioRoleControl(QObject *parent = nullptr); + + QAudio::Role audioRole() const override; + void setAudioRole(QAudio::Role role) override; + QList supportedAudioRoles() const override; + +private: + QAudio::Role m_role = QAudio::UnknownRole; +}; + +QT_END_NAMESPACE + +#endif // QANDROIDAUDIOROLECONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp new file mode 100644 index 000000000..cb7b5d0af --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qandroidcustomaudiorolecontrol.h" + +QT_BEGIN_NAMESPACE + +QAndroidCustomAudioRoleControl::QAndroidCustomAudioRoleControl(QObject *parent) + : QCustomAudioRoleControl(parent) +{ +} + +QString QAndroidCustomAudioRoleControl::customAudioRole() const +{ + return m_role; +} + +void QAndroidCustomAudioRoleControl::setCustomAudioRole(const QString &role) +{ + if (m_role == role) + return; + + m_role = role; + emit customAudioRoleChanged(m_role); +} + +QStringList QAndroidCustomAudioRoleControl::supportedCustomAudioRoles() const +{ + return QStringList() + << "CONTENT_TYPE_MOVIE" + << "CONTENT_TYPE_MUSIC" + << "CONTENT_TYPE_SONIFICATION" + << "CONTENT_TYPE_SPEECH" + << "USAGE_ALARM" + << "USAGE_ASSISTANCE_ACCESSIBILITY" + << "USAGE_ASSISTANCE_NAVIGATION_GUIDANCE" + << "USAGE_ASSISTANCE_SONIFICATION" + << "USAGE_ASSISTANT" + << "USAGE_GAME" + << "USAGE_MEDIA" + << "USAGE_NOTIFICATION" + << "USAGE_NOTIFICATION_COMMUNICATION_DELAYED" + << "USAGE_NOTIFICATION_COMMUNICATION_INSTANT" + << "USAGE_NOTIFICATION_COMMUNICATION_REQUEST" + << "USAGE_NOTIFICATION_EVENT" + << "USAGE_NOTIFICATION_RINGTONE" + << "USAGE_VOICE_COMMUNICATION" + << "USAGE_VOICE_COMMUNICATION_SIGNALLING"; +} + +QT_END_NAMESPACE diff --git a/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h new file mode 100644 index 000000000..4604ebe67 --- /dev/null +++ b/src/plugins/android/src/mediaplayer/qandroidcustomaudiorolecontrol.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QANDROIDCUSTOMAUDIOROLECONTROL_H +#define QANDROIDCUSTOMAUDIOROLECONTROL_H + +#include + +QT_BEGIN_NAMESPACE + +class QAndroidCustomAudioRoleControl : public QCustomAudioRoleControl +{ + Q_OBJECT +public: + explicit QAndroidCustomAudioRoleControl(QObject *parent = nullptr); + + QString customAudioRole() const override; + void setCustomAudioRole(const QString &role) override; + QStringList supportedCustomAudioRoles() const override; + +private: + QString m_role; +}; + +QT_END_NAMESPACE + +#endif // QANDROIDCUSTOMAUDIOROLECONTROL_H diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp index df1463a87..4bfcce5bc 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp +++ b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp @@ -250,6 +250,16 @@ void QAndroidMediaPlayerControl::setMuted(bool muted) Q_EMIT mutedChanged(muted); } +void QAndroidMediaPlayerControl::setAudioRole(QAudio::Role role) +{ + mMediaPlayer->setAudioRole(role); +} + +void QAndroidMediaPlayerControl::setCustomAudioRole(const QString &role) +{ + mMediaPlayer->setCustomAudioRole(role); +} + int QAndroidMediaPlayerControl::bufferStatus() const { return mBufferFilled ? 100 : 0; diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h index 119add7f8..35f56145f 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h +++ b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.h @@ -85,6 +85,8 @@ public Q_SLOTS: void stop() override; void setVolume(int volume) override; void setMuted(bool muted) override; + void setAudioRole(QAudio::Role role); + void setCustomAudioRole(const QString &role); private Q_SLOTS: void onVideoOutputReady(bool ready); diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp index 2688f3550..c057f530a 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp +++ b/src/plugins/android/src/mediaplayer/qandroidmediaservice.cpp @@ -41,16 +41,26 @@ #include "qandroidmediaplayercontrol.h" #include "qandroidmetadatareadercontrol.h" +#include "qandroidaudiorolecontrol.h" +#include "qandroidcustomaudiorolecontrol.h" #include "qandroidmediaplayervideorenderercontrol.h" QT_BEGIN_NAMESPACE QAndroidMediaService::QAndroidMediaService(QObject *parent) : QMediaService(parent) + , mAudioRoleControl(nullptr) + , mCustomAudioRoleControl(nullptr) , mVideoRendererControl(0) { mMediaControl = new QAndroidMediaPlayerControl; mMetadataControl = new QAndroidMetaDataReaderControl; + mAudioRoleControl = new QAndroidAudioRoleControl; + mCustomAudioRoleControl = new QAndroidCustomAudioRoleControl; + connect(mAudioRoleControl, &QAndroidAudioRoleControl::audioRoleChanged, + mMediaControl, &QAndroidMediaPlayerControl::setAudioRole); + connect(mCustomAudioRoleControl, &QAndroidCustomAudioRoleControl::customAudioRoleChanged, + mMediaControl, &QAndroidMediaPlayerControl::setCustomAudioRole); connect(mMediaControl, SIGNAL(mediaChanged(QMediaContent)), mMetadataControl, SLOT(onMediaChanged(QMediaContent))); connect(mMediaControl, SIGNAL(metaDataUpdated()), @@ -60,6 +70,8 @@ QAndroidMediaService::QAndroidMediaService(QObject *parent) QAndroidMediaService::~QAndroidMediaService() { delete mVideoRendererControl; + delete mCustomAudioRoleControl; + delete mAudioRoleControl; delete mMetadataControl; delete mMediaControl; } @@ -72,6 +84,12 @@ QMediaControl *QAndroidMediaService::requestControl(const char *name) if (qstrcmp(name, QMetaDataReaderControl_iid) == 0) return mMetadataControl; + if (qstrcmp(name, QAudioRoleControl_iid) == 0) + return mAudioRoleControl; + + if (qstrcmp(name, QCustomAudioRoleControl_iid) == 0) + return mCustomAudioRoleControl; + if (qstrcmp(name, QVideoRendererControl_iid) == 0) { if (!mVideoRendererControl) { mVideoRendererControl = new QAndroidMediaPlayerVideoRendererControl(mMediaControl); diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h index f78d05ddd..788c11098 100644 --- a/src/plugins/android/src/mediaplayer/qandroidmediaservice.h +++ b/src/plugins/android/src/mediaplayer/qandroidmediaservice.h @@ -46,6 +46,8 @@ QT_BEGIN_NAMESPACE class QAndroidMediaPlayerControl; class QAndroidMetaDataReaderControl; +class QAndroidAudioRoleControl; +class QAndroidCustomAudioRoleControl; class QAndroidMediaPlayerVideoRendererControl; class QAndroidMediaService : public QMediaService @@ -61,6 +63,8 @@ public: private: QAndroidMediaPlayerControl *mMediaControl; QAndroidMetaDataReaderControl *mMetadataControl; + QAndroidAudioRoleControl *mAudioRoleControl; + QAndroidCustomAudioRoleControl *mCustomAudioRoleControl; QAndroidMediaPlayerVideoRendererControl *mVideoRendererControl; }; diff --git a/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp b/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp index b81f98cbd..79685e16f 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp +++ b/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp @@ -223,6 +223,95 @@ void AndroidMediaPlayer::setDisplay(AndroidSurfaceTexture *surfaceTexture) surfaceTexture ? surfaceTexture->surfaceHolder() : 0); } +void AndroidMediaPlayer::setAudioRole(QAudio::Role role) +{ + QString str; + switch (role) { + case QAudio::MusicRole: + str = QLatin1String("CONTENT_TYPE_MUSIC"); + break; + case QAudio::VideoRole: + str = QLatin1String("CONTENT_TYPE_MOVIE"); + break; + case QAudio::VoiceCommunicationRole: + str = QLatin1String("USAGE_VOICE_COMMUNICATION"); + break; + case QAudio::AlarmRole: + str = QLatin1String("USAGE_ALARM"); + break; + case QAudio::NotificationRole: + str = QLatin1String("USAGE_NOTIFICATION"); + break; + case QAudio::RingtoneRole: + str = QLatin1String("USAGE_NOTIFICATION_RINGTONE"); + break; + case QAudio::AccessibilityRole: + str = QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY"); + break; + case QAudio::SonificationRole: + str = QLatin1String("CONTENT_TYPE_SONIFICATION"); + break; + case QAudio::GameRole: + str = QLatin1String("USAGE_GAME"); + break; + default: + break; + } + + setCustomAudioRole(str); +} + +void AndroidMediaPlayer::setCustomAudioRole(const QString &role) +{ + QStringList roles = role.split(",", QString::SkipEmptyParts); + + int type = 0; // CONTENT_TYPE_UNKNOWN + int usage = 0; // USAGE_UNKNOWN + for (int i = 0; i < qMin(2, roles.size()); ++i) { + auto r = roles[i]; + if (r == QLatin1String("CONTENT_TYPE_MOVIE")) + type = 3; + else if (r == QLatin1String("CONTENT_TYPE_MUSIC")) + type = 2; + else if (r == QLatin1String("CONTENT_TYPE_SONIFICATION")) + type = 4; + else if (r == QLatin1String("CONTENT_TYPE_SPEECH")) + type = 1; + else if (r == QLatin1String("USAGE_ALARM")) + usage = 4; + else if (r == QLatin1String("USAGE_ASSISTANCE_ACCESSIBILITY")) + usage = 11; + else if (r == QLatin1String("USAGE_ASSISTANCE_NAVIGATION_GUIDANCE")) + usage = 12; + else if (r == QLatin1String("USAGE_ASSISTANCE_SONIFICATION")) + usage = 13; + else if (r == QLatin1String("USAGE_ASSISTANT")) + usage = 16; + else if (r == QLatin1String("USAGE_GAME")) + usage = 14; + else if (r == QLatin1String("USAGE_MEDIA")) + usage = 1; + else if (r == QLatin1String("USAGE_NOTIFICATION")) + usage = 5; + else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_DELAYED")) + usage = 9; + else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_INSTANT")) + usage = 8; + else if (r == QLatin1String("USAGE_NOTIFICATION_COMMUNICATION_REQUEST")) + usage = 7; + else if (r == QLatin1String("USAGE_NOTIFICATION_EVENT")) + usage = 10; + else if (r == QLatin1String("USAGE_NOTIFICATION_RINGTONE")) + usage = 6; + else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION")) + usage = 2; + else if (r == QLatin1String("USAGE_VOICE_COMMUNICATION_SIGNALLING")) + usage = 3; + } + + mMediaPlayer.callMethod("setAudioAttributes", "(II)V", jint(type), jint(usage)); +} + static void onErrorNative(JNIEnv *env, jobject thiz, jint what, jint extra, jlong id) { Q_UNUSED(env); diff --git a/src/plugins/android/src/wrappers/jni/androidmediaplayer.h b/src/plugins/android/src/wrappers/jni/androidmediaplayer.h index a7284bb0c..14cbf49bc 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.h +++ b/src/plugins/android/src/wrappers/jni/androidmediaplayer.h @@ -42,6 +42,7 @@ #include #include +#include QT_BEGIN_NAMESPACE @@ -116,6 +117,8 @@ public: void setVolume(int volume); bool setPlaybackRate(qreal rate); void setDisplay(AndroidSurfaceTexture *surfaceTexture); + void setAudioRole(QAudio::Role role); + void setCustomAudioRole(const QString &role); static bool initJNI(JNIEnv *env); -- cgit v1.2.3