我有一个非常简单的应用程序,我已经构建来测试AVAudioPlayer.我有一个16s的aif文件在我的Mac上播放得很好.把它放在一个简单的应用程序中,然后在我的iPhone上运行但没有声音.向对象发送'play'会返回成功,audioPlayerDidFinishPlaying会在16秒后成功返回.仍然没有声音.检查了iPhone上的音量,就好了.已检查以确保我的AVAudioPlayer对象的卷设置为1.0 - 确实如此.有人可以帮忙吗?
这是我的代码
NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"Soothing" ofType:@"aif"];
NSURL *playURL = [NSURL fileURLWithPath:soundPath];
NSError *error;
self.myAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:playURL error:&error];
NSLog(@"About to play sound");
self.myAudioPlayer.delegate = self;
[self.myAudioPlayer prepareToPlay];
bool success = [self.myAudioPlayer play];
if (!success) {
NSLog(@"Failed to play file");
} else NSLog(@"Looks like it succeded");
Run Code Online (Sandbox Code Playgroud) 有一个简单的 NavigationView,两侧都有固定的内容。左窗格仅显示几个按钮,右窗格显示使用 NSViewRepresentable 包装的 NSView 的图形。在 iPad 上以纵向模式查看时,左窗格会按预期消失,但不会显示“后退”按钮。可以单击预期“后退”按钮的区域,然后显示左窗格。那里什么也看不见。
我究竟做错了什么?
var body: some View {
NavigationView {
VStack(alignment: .center) {
Text("This is the left side")
Button {
...
} label: {
Text("Create Estimate")
}.foregroundColor(Color.black)
Button {
...
} label: {
Text("Reset Results")
}.foregroundColor(Color.black)
Text("This is the end of the left side")
}
VStack {
Text("This is the right side")
AreaChartView(redrawCount: redrawCounter, scenario: activeScenario)
}
}
}
Run Code Online (Sandbox Code Playgroud)
}
更新:即使我注释掉上面导航视图中的所有内容并替换为:也会发生这种情况
NavigationView {
Text("This is the left side")
Text("This is the right side")
} …Run Code Online (Sandbox Code Playgroud)