gpt4 book ai didi

ios - Flutter 应用程序的音频无法通过扬声器工作

转载 作者:行者123 更新时间:2023-12-03 02:28:20 52 4
gpt4 key购买 nike

我无法让我的 flutter 应用程序通过 iOS 扬声器播放音频。我在多个 iOS 设备上尝试过。音频通过 android 扬声器、android 耳机和 iOS 耳机播放。我没有收到有关它的错误消息,并且根据显示音频文件位置更改的日志消息,音频似乎正在播放。

我正在使用包音频播放器
(https://pub.dartlang.org/packages/audioplayer)

我什至尝试过运行示例( https://pub.dartlang.org/packages/audioplayer#-example-tab- ),但我遇到了同样的问题。

我也尝试过使用包音频播放器( https://pub.dartlang.org/packages/audioplayers )。一样。如果有人能指出我的任何解释......我想我需要以某种方式默认扬声器,但我找不到任何关于如何在 flutter 中做到这一点的文档,而且我还没有学会如何覆盖某些方面具有 native swift/objective c 代码的 flutter 应用程序。如果有人有任何建议,我很想听听他们的意见。

附件是有和没有插入我的 iPhone 的耳机的日志。

带耳机:

flutter: attempting to play /var/mobile/Containers/Data/Application/1A17D73F-0130-4A6B-A1F4-B44ECAB4EF3E/Documents/English_mit_filler_David.mp3
iOS => call play
iOS => playerId dd4d9d29-2188-4795-abfb-6d785c6c19a7
play!
isLocal: 1 1
volume: 1.000000 1
togglePlay /var/mobile/Containers/Data/Application/1A17D73F-0130-4A6B-A1F4-B44ECAB4EF3E/Documents/English_mit_filler_David.mp3
ios -> updateDuration...nan
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
ios -> onTimeInterval...
player status: 1
ios -> updateDuration...19.435102
ios -> invokechannel
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
ios -> onTimeInterval...
ios -> onTimeInterval...
flutter: _AudioAppState.setDurationHandler => d 0:00:19.435000
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.200000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.401000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.600000
ios -> onTimeInterval...

不带耳机:
flutter: attempting to play /var/mobile/Containers/Data/Application/1A17D73F-0130-4A6B-A1F4-B44ECAB4EF3E/Documents/English_mit_filler_Dropbox.mp3
iOS => call play
iOS => playerId 60dc6e8c-4619-4abb-812d-33dcb03f23a8
play!
isLocal: 1 1
volume: 1.000000 1
togglePlay /var/mobile/Containers/Data/Application/1A17D73F-0130-4A6B-A1F4-B44ECAB4EF3E/Documents/English_mit_filler_Dropbox.mp3
ios -> updateDuration...nan
ios -> onTimeInterval...
ios -> onTimeInterval...
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
player status: 1
ios -> updateDuration...28.682449
ios -> invokechannel
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
flutter: _AudioAppState.setDurationHandler => d 0:00:28.682000
ios -> onTimeInterval...
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
flutter: _AudioAppState.setPositionHandler => p 0:00:00.000000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.201000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.401000
ios -> onTimeInterval...
flutter: _AudioAppState.setPositionHandler => p 0:00:00.601000
ios -> onTimeInterval...

对我来说看起来像相同的日志,两端都没有错误。但这就像声音被静音了-我确保请勿打扰模式未打开,静音模式未打开,我已检查手机侧面静音按钮上的按钮未打开...我已经通过 Xcode 在模拟器上进行了尝试,然后确实播放了音频......但我不知道如何让它在我的物理设备上工作。
感谢您的任何建议!

最佳答案

在此链接 AVAudioSession setCategory error 的帮助下,我设法解决了它

我将以下代码添加到在 ios/Pods/.symlinks/plugins/audioplayer/ios/Classes 中创建的 AudioplayerPlugin.m 文件中

-(void) togglePlay: (NSString*) url isLocal: (int) isLocal
{
//ADDED START
NSError *error = nil;
BOOL success = [[AVAudioSession sharedInstance]
setCategory:AVAudioSessionCategoryPlayback
error:&error];
if (!success) {
NSLog(@"Error setting speaker");
// Handle error here, as appropriate
}
//ADDED END
NSLog(@"togglePlay %@",url );
if (![lastUrl isEqualToString:url]) {
[playerItem removeObserver:self
forKeyPath:@"player.currentItem.status"];

关于ios - Flutter 应用程序的音频无法通过扬声器工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50616323/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com