Skip to content

Commit

Permalink
Merge pull request #12714 from fwcd/ios-avaudiosession
Browse files Browse the repository at this point in the history
SoundManager: Set up `AVAudioSession` on iOS
  • Loading branch information
daschuer authored Feb 3, 2024
2 parents 235b45a + d34ab92 commit ad84046
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
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;
[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

0 comments on commit ad84046

Please sign in to comment.