gpt4 book ai didi

audio_waveforms can't find audio file(音频波形找不到音频文件(_W))

转载 作者:bug小助手 更新时间:2023-10-25 18:52:49 24 4
gpt4 key购买 nike



I am using audio_waveforms to handle audio messages inside my chat app. I am facing a problem where when I try to call await player.preparePlayer(path: path); to prepare my player where the path is given with the message. I am currently testing with local .wav audio files located in my assets/audio. I added the folder in my pubspec.yaml. I am creating late PlayerController player; in GroupMessage class and then call
Future initializePlayer(String path) async { player = PlayerController(); await player.preparePlayer(path: path); }

我正在使用AUDIO_WAVERFORMS在我的聊天应用程序中处理音频消息。我正面临一个问题,当我试图调用await player.prepararePlayer(Path:Path);来准备我的播放器时,给出的路径是带有消息的。我目前正在使用位于我的资源/音频中的本地.wav音频文件进行测试。我在pubspec.yaml中添加了该文件夹。我正在GroupMessage类中创建Late PlayerControl Player;,然后调用Future InitializePlayer(字符串路径)异步{Player=PlayerControl();等待Player.prepararePlayer(Path:Path);}


using a FutureBuilder so that I can wait for the controller to be initialized correctly. But it throws the following error:

使用FutureBuilder,以便我可以等待控制器正确初始化。但它会抛出以下错误:


E/ExoPlayerImplInternal( 6022): Playback error
E/ExoPlayerImplInternal( 6022): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/ExoPlayerImplInternal( 6022): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:644)
E/ExoPlayerImplInternal( 6022): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:616)
E/ExoPlayerImplInternal( 6022): at android.os.Handler.dispatchMessage(Handler.java:102)
E/ExoPlayerImplInternal( 6022): at android.os.Looper.loop(Looper.java:223)
E/ExoPlayerImplInternal( 6022): at android.os.HandlerThread.run(HandlerThread.java:67)
E/ExoPlayerImplInternal( 6022): Caused by: com.google.android.exoplayer2.upstream.FileDataSource$FileDataSourceException: java.io.FileNotFoundException: assets/audio/arabian-psy-vox_138bpm_F.wav: open failed: ENOENT (No such file or directory)

I don't know why it can't see the file, can someone help me

我不知道为什么它看不到文件,有人能帮帮我吗


更多回答
优秀答案推荐

I found a solution & it needs a package named path_provider.

我找到了一个解决方案&它需要一个名为PATH_PROVIDER的包。


So, your pubspec.yaml file should look like this:

因此,您的pubspec.yaml文件应该如下所示:


flutter:
uses-material-design: true
assets:
- assets/sound.wav

Here's the main.dart file. So, here's a different way in this plugin if your sound file is not in the native folder.

这是main.dart文件。所以,如果你的声音文件不在本地文件夹中,这里有一种不同的方式。


import "dart:io";

import "package:audio_waveforms/audio_waveforms.dart";
import "package:flutter/material.dart";
import "package:flutter/services.dart";
import "package:path_provider/path_provider.dart";

void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyWidget(),
debugShowCheckedModeBanner: false,
);
}
}

class MyWidget extends StatefulWidget {
const MyWidget({super.key});

@override
State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
final PlayerController controller = PlayerController();
String path = "";

@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(Duration timeStamp) async {
final Directory directory = await getApplicationDocumentsDirectory();
const String assetName = "sound.wav";
final File file = File("${directory.path}/$assetName");
final ByteData byteData = await rootBundle.load("assets/$assetName");
await file.writeAsBytes(byteData.buffer.asUint8List());
path = file.path;
setState(() {});
},
);
}

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
AudioFileWaveforms(
size: const Size(double.infinity, 100),
playerController: controller,
playerWaveStyle: const PlayerWaveStyle(
liveWaveColor: Colors.blueAccent,
),
),
ElevatedButton(
onPressed: () async {
if (controller.playerState.isPlaying) {
await controller.stopPlayer();
} else {}
await controller.preparePlayer(path: path);
await controller.startPlayer();
},
child: const Text("Play"),
)
],
),
),
),
);
}
}

更多回答

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