Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoundManager: Set up AVAudioSession on iOS #12714

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,7 @@ if(APPLE)

if(IOS)
target_sources(mixxx-lib PRIVATE
src/soundio/soundmanagerios.mm
src/util/screensaverios.mm
)
else()
Expand Down
8 changes: 8 additions & 0 deletions src/soundio/soundmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <QLibrary>
#include <QThread>
#include <QtGlobal>
#include <cstring> // for memcpy and strcmp

#include "control/controlobject.h"
Expand All @@ -22,6 +23,10 @@
#include "util/versionstore.h"
#include "vinylcontrol/defs_vinylcontrol.h"

#ifdef Q_OS_IOS
#include "soundio/soundmanagerios.h"
#endif

typedef PaError (*SetJackClientName)(const char *name);

namespace {
Expand Down Expand Up @@ -249,6 +254,9 @@ void SoundManager::queryDevicesPortaudio() {
if (!m_paInitialized) {
#ifdef Q_OS_LINUX
setJACKName();
#endif
#ifdef Q_OS_IOS
mixxx::initializeAVAudioSession();
#endif
err = Pa_Initialize();
m_paInitialized = true;
Expand Down
7 changes: 7 additions & 0 deletions src/soundio/soundmanagerios.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace mixxx {

void initializeAVAudioSession();

}; // namespace mixxx
31 changes: 31 additions & 0 deletions src/soundio/soundmanagerios.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <QDebug>
#include <QtGlobal>

#import <AVFAudio/AVFAudio.h>

namespace mixxx {

void initializeAVAudioSession() {
AVAudioSession* session = AVAudioSession.sharedInstance;
AVAudioSessionCategory category = AVAudioSessionCategoryPlayback;
AVAudioSessionMode mode = AVAudioSessionModeDefault;
AVAudioSessionCategoryOptions options =
AVAudioSessionCategoryOptionMixWithOthers |
AVAudioSessionCategoryOptionAllowAirPlay |
AVAudioSessionCategoryOptionAllowBluetoothA2DP;

NSError* error = nil;
daschuer marked this conversation as resolved.
Show resolved Hide resolved
[session setCategory:category mode:mode options:options error:&error];
if (error != nil) {
qWarning() << "Could not initialize AVAudioSession:"
<< error.localizedDescription;
}

[session setActive:true error:&error];
if (error != nil) {
qWarning() << "Could not activate AVAudioSession:"
<< error.localizedDescription;
}
}

}; // namespace mixxx
Loading