'audioplayers/AudioplayersPlugin.h' file not found in flutter
4,402
I had this issue too and just needed to install CocoaPods.
brew install cocoapods
pod setup
There's an error that indicates you need to do this, but it's buried in the build output.
Comments
-
Yash Jain over 1 year
Unable to use audio in flutter for ios development
This is my code : pubspec.yaml (using audioplayers: ^0.7.8 plugin for playing audio)
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 file Importing audio_cache.dart file to play the audio. I have imported the audio files in assets folder of the project. The same code works fine in the android devices
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(); }, ) ], ), ); } }
Getting the following error while running this project in iOS device using 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>
The above code run proper without using audio file. If there is something that i am missing to add, please tell me, and I am using Microsoft visual Studio Code as my IDE
-
Yash Jain about 5 yearsI tried the above command, but getting the error message pod setup command not working. If you get this error, then in Mac open terminal and type: rm -rf ~/.cocoapods/repos then type pod setup command