我使用RedaPro for Xamarin连接到音频投射。声音传到扬声器。收听时,我连接了蓝牙耳机。声音切换到它们,但是很安静。
对于声音,我使用具有以下设置的AVAudioSession:
类别-PlayAndRecord
CategoryOptions -DefaultToSpeaker |蓝牙| AllowBluetoothA2DP
并激活会话
设置AVAudioSession代码:
private static void SetupAVSession()
{
AVAudioSession.SharedInstance().SetActive(false);
AVAudioSession.SharedInstance().SetCategory(AVAudioSessionCategory.PlayAndRecord,
AVAudioSessionCategoryOptions.DefaultToSpeaker | AVAudioSessionCategoryOptions.AllowBluetooth | AVAudioSessionCategoryOptions.AllowBluetoothA2DP);
AVAudioSession.SharedInstance().SetActive(true);
}
答案 0 :(得分:1)
我将SetPreferredSampleRate的值设置为16000,并且可以正常工作
final class NavigationStack: ObservableObject {
enum Direction {
case root
case forward
case backward
}
@Published var viewStack: [NavigationItem] = []
@Published var currentView: NavigationItem
@Published var navigate: Direction = .root
init(_ currentView: NavigationItem ){
self.currentView = currentView
}
func unwind(){
if viewStack.count == 0{
return
}
let last = viewStack.count - 1
currentView = viewStack[last]
withAnimation {
self.navigate = .backward
}
viewStack.remove(at: last)
}
func advance(_ view:NavigationItem){
viewStack.append( currentView)
currentView = view
withAnimation {
self.navigate = .forward
}
}
func home( ){
currentView = NavigationItem(view: AnyView(HomeView()))
viewStack.removeAll()
withAnimation {
self.navigate = .root
}
}
}
struct NavigationHost: View{
@EnvironmentObject var navigation: NavigationStack
var body: some View {
ZStack(alignment: .topLeading) {
if navigation.navigate == .root {
self.navigation.currentView.view
}
else if navigation.navigate == .backward {
self.navigation.currentView.view
.transition(.move(edge: .leading))
}
if navigation.navigate == .forward {
self.navigation.currentView.view
.transition(.move(edge: .trailing))
}
}
}
}