diff options
Diffstat (limited to 'src/plugins/android')
14 files changed, 476 insertions, 7 deletions
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..5a0462338 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 @@ -41,11 +41,13 @@ package org.qtproject.qt5.android.multimedia; import java.io.IOException; import java.lang.String; +import java.util.HashMap; 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 +67,8 @@ public class QtAndroidMediaPlayer native public void onStateChangedNative(int state, long id); private MediaPlayer mMediaPlayer = null; + private AudioAttributes mAudioAttributes = null; + private HashMap<String, String> mHeaders = null; private Uri mUri = null; private final long mID; private final Context mContext; @@ -235,6 +239,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); } } @@ -341,6 +346,16 @@ public class QtAndroidMediaPlayer } } + public void initHeaders() + { + mHeaders = new HashMap<String, String>(); + } + + public void setHeader(final String header, final String value) + { + mHeaders.put(header, value); + } + public void setDataSource(final String path) { if ((mState & State.Uninitialized) != 0) @@ -378,7 +393,10 @@ public class QtAndroidMediaPlayer FileDescriptor fd = fis.getFD(); mMediaPlayer.setDataSource(fd); } else { - mMediaPlayer.setDataSource(path); + if (mHeaders.isEmpty()) + mMediaPlayer.setDataSource(path); + else + mMediaPlayer.setDataSource(mContext, mUri, mHeaders); } setState(State.Initialized); } catch (final IOException e) { @@ -547,4 +565,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/common/qandroidvideooutput.cpp b/src/plugins/android/src/common/qandroidvideooutput.cpp index a8351aadb..083ceff24 100644 --- a/src/plugins/android/src/common/qandroidvideooutput.cpp +++ b/src/plugins/android/src/common/qandroidvideooutput.cpp @@ -320,7 +320,7 @@ void QAndroidTextureVideoOutput::onFrameAvailable() return; QAbstractVideoBuffer *buffer = new AndroidTextureVideoBuffer(this, m_nativeSize); - QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_BGR32); + QVideoFrame frame(buffer, m_nativeSize, QVideoFrame::Format_ABGR32); if (m_surface->isActive() && (m_surface->surfaceFormat().pixelFormat() != frame.pixelFormat() || m_surface->surfaceFormat().frameSize() != frame.size())) { 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<QAudio::Role> QAndroidAudioRoleControl::supportedAudioRoles() const +{ + return QList<QAudio::Role>() + << 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 <qaudiorolecontrol.h> + +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<QAudio::Role> 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 <qcustomaudiorolecontrol.h> + +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..13a8cdbbb 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; @@ -374,7 +384,7 @@ void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent, if ((mMediaPlayer->display() == 0) && mVideoOutput) mMediaPlayer->setDisplay(mVideoOutput->surfaceTexture()); - mMediaPlayer->setDataSource(mediaContent.canonicalUrl().toString(QUrl::FullyEncoded)); + mMediaPlayer->setDataSource(mediaContent.canonicalRequest()); mMediaPlayer->prepareAsync(); } 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..f899481f0 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp +++ b/src/plugins/android/src/wrappers/jni/androidmediaplayer.cpp @@ -166,9 +166,17 @@ void AndroidMediaPlayer::setMuted(bool mute) mMediaPlayer.callMethod<void>("mute", "(Z)V", jboolean(mute)); } -void AndroidMediaPlayer::setDataSource(const QString &path) +void AndroidMediaPlayer::setDataSource(const QNetworkRequest &request) { - QJNIObjectPrivate string = QJNIObjectPrivate::fromString(path); + QJNIObjectPrivate string = QJNIObjectPrivate::fromString(request.url().toString(QUrl::FullyEncoded)); + + mMediaPlayer.callMethod<void>("initHeaders", "()V"); + for (auto &header : request.rawHeaderList()) { + auto value = request.rawHeader(header); + mMediaPlayer.callMethod<void>("setHeader", "(Ljava/lang/String;Ljava/lang/String;)V", + QJNIObjectPrivate::fromString(header).object(), QJNIObjectPrivate::fromString(value).object()); + } + mMediaPlayer.callMethod<void>("setDataSource", "(Ljava/lang/String;)V", string.object()); } @@ -223,6 +231,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<void>("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..37c7456f7 100644 --- a/src/plugins/android/src/wrappers/jni/androidmediaplayer.h +++ b/src/plugins/android/src/wrappers/jni/androidmediaplayer.h @@ -41,7 +41,9 @@ #define ANDROIDMEDIAPLAYER_H #include <QObject> +#include <QNetworkRequest> #include <QtCore/private/qjni_p.h> +#include <QAudio> QT_BEGIN_NAMESPACE @@ -111,11 +113,13 @@ public: void stop(); void seekTo(qint32 msec); void setMuted(bool mute); - void setDataSource(const QString &path); + void setDataSource(const QNetworkRequest &request); void prepareAsync(); 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); diff --git a/src/plugins/android/videonode/qandroidsgvideonodeplugin.cpp b/src/plugins/android/videonode/qandroidsgvideonodeplugin.cpp index e69c9c16e..d70c8100b 100644 --- a/src/plugins/android/videonode/qandroidsgvideonodeplugin.cpp +++ b/src/plugins/android/videonode/qandroidsgvideonodeplugin.cpp @@ -48,7 +48,7 @@ QList<QVideoFrame::PixelFormat> QAndroidSGVideoNodeFactoryPlugin::supportedPixel QList<QVideoFrame::PixelFormat> pixelFormats; if (handleType == QAbstractVideoBuffer::GLTextureHandle) - pixelFormats.append(QVideoFrame::Format_BGR32); + pixelFormats.append(QVideoFrame::Format_ABGR32); return pixelFormats; } |