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

Bluetooth headphone support #148

Merged
merged 6 commits into from
Jan 9, 2024
Merged
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
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
Loading