ios - 在 flutter 中找不到“audioplayers/AudioplayersPlugin.h”文件

标签 ios swift audio dart flutter

无法在flutter中使用音频进行ios开发

这是我的代码: pubspec.yaml(使用audioplayers:^0.7.8插件来播放音频)

name: play_audio
    dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^0.1.2
  # lib for adding sound
  audioplayers: ^0.7.8

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/sound/correct_answer.mp3
    - assets/sound/wrong_answer.mp3

play_audio.dart 文件 导入audio_cache.dart文件来播放音频。我已将音频文件导入到项目的 Assets 文件夹中。 相同的代码在 Android 设备中运行良好

import 'package:audioplayers/audio_cache.dart';
import "package:flutter/material.dart";

// audio file path
const correctSoundPath = "sound/correct_answer.mp3";
const inCorrectSoundPath = "sound/wrong_answer.mp3";

class PlayAudio extends StatefulWidget {
  _PlayAudioState createState() => _PlayAudioState();
}

class _PlayAudioState extends State<PlayAudio> {
  AudioCache player;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    player = AudioCache(); // initialising audio cache
    debugPrint("inside initState");
  }

  Future _playCorrect() async {
    player.play(correctSoundPath);
    debugPrint("inside _playCorrect()");
  }

  Future _playIncorrect() async {
    player.play(inCorrectSoundPath);
    debugPrint("inside _playIncorrect()");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          // correct button
          MaterialButton(
            child: Text("Correct"),
            onPressed: () {
              _playCorrect();
            },
          ),

          // incorrect button
          MaterialButton(
            child: Text("Incorrect"),
            onPressed: () {
              _playIncorrect();
            },
          )
        ],
      ),
    );
  }
}

使用 flutter run 在 iOS 设备中运行此项目时出现以下错误:

    Error output from Xcode build:
    ** BUILD FAILED **

Xcode's output:

    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
    Debug.xcconfig line 1: Unable to find included file "Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig"
    Debug.xcconfig line 1: Unable to find included file "Pods/Target Support
    Files/Pods-Runner/Pods-Runner.debug.xcconfig"
    === BUILD TARGET Runner OF PROJECT Runner WITH CONFIGURATION Debug ===
    /Users/quiz/Documents/Project/Flutter_Project/TODO_Flutter_Projects/Quiz/multiple_choice_ios/ios/Runner/Genera
    tedPluginRegistrant.m:6:9: fatal error: 'audioplayers/AudioplayersPlugin.h' file not found
    #import <audioplayers/AudioplayersPlugin.h>

上面的代码在不使用音频文件的情况下运行正常。如果我有什么需要补充的,请告诉我,我正在使用 Microsoft Visual Studio Code 作为我的 IDE

最佳答案

我也遇到了这个问题,只需要安装 CocoaPods。

brew install cocoapods
pod setup

有一个错误表明您需要执行此操作,但它隐藏在构建输出中。

关于ios - 在 flutter 中找不到“audioplayers/AudioplayersPlugin.h”文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54397063/

相关文章:

c++ - 如何在 Qt 上运行 AudioOutput 示例代码?

iphone - iPhone上的Facebook Connect

objective-c - for循环中的 objective-c 内存管理

ios - UIDynamicAnimator 停止对重力变化使用react

ios - iPhone同时声音输出

javascript - Html5 音频时间更新精度

ios - xcode项目中我的数据库文件在哪里

ios - 类消息的接收方“SMClient”是前向声明

ios - 无法让 Swift 使用我的通用 == 运算符

ios - Swift 将字符串转换为日期输出错误的日期