【问题标题】:'audioplayers/AudioplayersPlugin.h' file not found in flutter在颤振中找不到“audioplayers/AudioplayersPlugin.h”文件
【发布时间】:2019-06-21 03:57:09
【问题描述】:

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

这是我的代码: pubspec.yaml(使用音频播放器:^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 文件以播放音频。我已经在项目的资产文件夹中导入了音频文件。 相同的代码在 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();
            },
          )
        ],
      ),
    );
  }
}

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

    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

【问题讨论】:

    标签: ios swift audio dart flutter


    【解决方案1】:

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

    brew install cocoapods
    pod setup
    

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

    【讨论】:

    • 我尝试了上述命令,但收到错误消息 pod setup 命令不起作用。如果您收到此错误,请在 Mac 中打开终端并输入:rm -rf ~/.cocoapods/repos 然后输入 pod setup 命令
    猜你喜欢
    • 1970-01-01
    • 2021-07-04
    • 2021-01-06
    • 1970-01-01
    • 2020-08-18
    • 1970-01-01
    • 2020-11-15
    • 1970-01-01
    • 2020-10-21
    相关资源
    最近更新 更多