我无法让我的扑动应用程序通过iOS扬声器播放音频。我试过多个iOS设备。音频通过Android扬声器,Android耳机和iOS耳机播放。我没有收到任何关于它的错误消息,并且音频似乎是根据显示音频文件位置变化的日志消息播放的。
我使用的是audioplayer包 (https://pub.dartlang.org/packages/audioplayer)
我甚至试过运行示例(https://pub.dartlang.org/packages/audioplayer#-example-tab-),我也遇到了同样的问题。
我也尝试过使用audioplayers包(https://pub.dartlang.org/packages/audioplayers)。一样。如果有人能指出我的任何解释...我想我需要以某种方式默认发言者,但我找不到任何关于如何做到这一点的文件,我还没有学会如何覆盖某些方面一个颤动的应用程序与本机swift / objective c代码。如果有人有任何建议,我很乐意听到。
附上带有和不带耳机插入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在模拟器上尝试了它,然后音频确实播放了...但我无法弄清楚如何让它在我的物理设备上工作。 谢谢你的建议!
答案 0 :(得分:0)
我设法在此链接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"];
答案 1 :(得分:-1)
只需在<uses-permission android:name="android.permission.INTERNET"/>
结束标记之后将</application>
添加到您的AndroidManifest.xml文件中。