gpt4 book ai didi

ios - 导入音频播放器包后无法运行 flutter

转载 作者:IT王子 更新时间:2023-10-29 07:02:55 26 4
gpt4 key购买 nike

我从 flutter 包中导入了以下声音包。

audioplayers: ^0.12.1

它抛出错误提示我需要安装一些东西。根据错误消息,我运行了以下命令。

brew install cocoa

pods pod setup

设置成功完成。

此后当我尝试运行我的应用程序时它开始抛出错误。该应用程序不过是一个带有空 MaterialApp() 小部件的无状态小部件。在我进行上述安装之前,它运行良好。

我尝试删除音频播放器依赖项,但错误仍然存​​在。尝试重建并重新启动我的 IDE 没有帮助。请指教有什么问题。我不明白为什么即使在删除依赖项后错误仍然存​​在。如果重要的话,我正在使用 Mac。请指教。谢谢。

错误日志:

Launching lib/main.dart on iPhone X in debug mode...
Running pod install...
Running Xcode build...
Xcode build done. 1.9s
Failed to build iOS app
Error output from Xcode build:

** BUILD FAILED **


Xcode's output:

=== BUILD TARGET path_provider OF PROJECT Pods WITH CONFIGURATION Debug ===
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:232:5: error: use of undeclared identifier 'AVAudioSessionCategory'; did you mean 'AVAudioSessionCategoryRecord'?
AVAudioSessionCategory category;
^~~~~~~~~~~~~~~~~~~~~~
AVAudioSessionCategoryRecord
In module 'AVFoundation' imported from /Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:4:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.2.sdk/System/Library/Frameworks/AVFoundation.framework/Frameworks/AVFAudio.framework/Headers/AVAudioSession.h:642:28: note: 'AVAudioSessionCategoryRecord' declared here
AVF_EXPORT NSString *const AVAudioSessionCategoryRecord;
^
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:232:27: error: expected ';' after expression
AVAudioSessionCategory category;
^
;
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:232:28: error: use of undeclared identifier 'category'
AVAudioSessionCategory category;
^
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:234:9: error: use of undeclared identifier 'category'
category = AVAudioSessionCategoryAmbient;
^
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:236:9: error: use of undeclared identifier 'category'
category = AVAudioSessionCategoryPlayback;
^
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:239:34: error: use of undeclared identifier 'category'
setCategory: category
^
/Users/myusername/.pub-cache/hosted/pub.dartlang.org/audioplayers-0.12.1/ios/Classes/AudioplayersPlugin.m:232:5: warning: expression result unused [-Wunused-value]
AVAudioSessionCategory category;
^~~~~~~~~~~~~~~~~~~~~~
1 warning and 6 errors generated.

Could not build the application for the simulator.
Error launching application on iPhone X.

最佳答案

我有一个解决方案,尽管我承认这不是最好的解决方案。

我的猜测是错误与 Xcode 试图将其构建为通用应用程序而不是 iOS 应用程序有关,尽管我对 Xcode 的了解还不足以验证这一点(我主要是一名使用 Flutter 的 Android 开发人员). AVAudioSessionCategory 不适用于 MacOS...仅适用于 iOS。

构建后,出现与上述相同的错误。在 AudioplayersPlugin.m 的第 232 行中,您会看到:

AVAudioSessionCategory category;
if (respectSilence) {
category = AVAudioSessionCategoryAmbient;
} else {
category = AVAudioSessionCategoryPlayback;
}
BOOL success = [[AVAudioSession sharedInstance]
setCategory: category
error:&error];

替换为:

BOOL success;
if (respectSilence) {
success = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryAmbient
error:&error];
} else {
success = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error:&error];
}

您的应用现在应该可以在 iOS 上运行。

关于ios - 导入音频播放器包后无法运行 flutter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56639785/

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