flutter 音频播放器无法播放我的文件,我该怎么办?

8iwquhpp  于 2023-05-23  发布在  Flutter
关注(0)|答案(1)|浏览(213)

我只是想添加音频播放器酒吧到我的应用程序。但它会出错,比如:

resetDrmState:  mDrmInfo=null mDrmProvisioningThread=null mPrepareDrmInProgress=false mActiveDrmScheme=false

我尝试了Stackoverflow中发布的所有问题。但我不明白。
这是我的代码:

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

  @override
  State<MyApp> createState() => _MyAppState();
}

final player = AudioPlayer();

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("data"),
        ),
        body: Center(
          child: TextButton(
            onPressed: () {
              player.setSource(AssetSource("sound/n1.wav"));
            },
            child: Text("data"),
          ),
        ),
      ),
    );
  }
}

我试过的资源有哪些:

x759pob2

x759pob21#

这对我有帮助:

final player = AudioPlayer();

final bundle = await rootBundle.load("sound/n1.wav");

final bytes = bytes.buffer.asUint8List(bundle.offsetInBytes, bundle.lengthInBytes);

final status = await player.playBytes(audiobytes);

if (status == 1) {
 // playing
}

相关问题