Skip to content

Commit

Permalink
Merge pull request #148 from emurray2/bluetooth-support
Browse files Browse the repository at this point in the history
Bluetooth headphone support
  • Loading branch information
NickCulbertson committed Jan 9, 2024
2 parents cdc782e + d42c183 commit 7c39bac
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AudioKitEX
import AudioKitUI
import SwiftUI

class MultiSegmentPlayerConductor: ObservableObject {
class MultiSegmentPlayerConductor: ObservableObject, HasAudioEngine {
let engine = AudioEngine()
let player = MultiSegmentAudioPlayer()

Expand Down Expand Up @@ -105,7 +105,11 @@ class MultiSegmentPlayerConductor: ObservableObject {

func setAudioSessionCategoriesWithOptions() {
do {
try AudioKit.Settings.session.setCategory(.playAndRecord, options: [.defaultToSpeaker, .mixWithOthers])
try AudioKit.Settings.session.setCategory(.playAndRecord,
options: [.defaultToSpeaker,
.mixWithOthers,
.allowBluetooth,
.allowBluetoothA2DP])
try AudioKit.Settings.session.setActive(true)
} catch {
assertionFailure(error.localizedDescription)
Expand All @@ -126,7 +130,7 @@ class MultiSegmentPlayerConductor: ObservableObject {
}

struct MultiSegmentPlayerView: View {
@ObservedObject var conductor = MultiSegmentPlayerConductor()
@StateObject var conductor = MultiSegmentPlayerConductor()

var currentTimeText: String {
let currentTime = String(format: "%.1f", conductor.timeStamp)
Expand Down Expand Up @@ -164,6 +168,12 @@ struct MultiSegmentPlayerView: View {
Spacer()
}
.navigationBarTitle(Text("Multi Segment Player"))
.onAppear {
conductor.start()
}
.onDisappear {
conductor.stop()
}
}

struct PlayPauseView: View {
Expand Down

0 comments on commit 7c39bac

Please sign in to comment.