dart 音频是不播放只是音频包

zbdgwd5y  于 2023-03-15  发布在  其他
关注(0)|答案(1)|浏览(148)

我已经给了所有的许可,但它不起作用

class MusicPlayer extends StatefulWidget {
  MusicPlayer({super.key, this.url});
  String? url;

  @override
  State<MusicPlayer> createState() => _MusicPlayerState();
}

class _MusicPlayerState extends State<MusicPlayer> {
  late AudioPlayer _audioPlayer;

  @override
  void initState() {
    _audioPlayer = AudioPlayer()..setAsset(widget.url!, preload: true);

    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    print(widget.url);
    return Scaffold(
        appBar: cAppBar('Music Player'),
        bottomNavigationBar: CBottomNav(
          selected: "2",
        ),
        body: Column(
          children: [
            Controls(audioPlayer: _audioPlayer),
          ],
        ));
  }
}

class Controls extends StatelessWidget {
  const Controls({Key? key, required this.audioPlayer}) : super(key: key);

  final AudioPlayer audioPlayer;
  @override
  Widget build(BuildContext context) {
    return StreamBuilder<PlayerState>(
      stream: audioPlayer.playerStateStream,
      builder: (context, snapshot) {
        final playerState = snapshot.data;
        final processingState = playerState?.processingState;
        final playing = playerState?.playing;

        if (!(playing ?? false)) {
          return IconButton(
              onPressed: audioPlayer.play,
              iconSize: 80,
              color: Colors.black,
              icon: const Icon(Icons.play_arrow));
        } else if (processingState != ProcessingState.completed) {
          return IconButton(
              onPressed: audioPlayer.pause,
              iconSize: 80,
              color: Colors.black,
              icon: const Icon(Icons.pause));
        }
        return const Icon(
          Icons.play_arrow,
          size: 80,
          color: Colors.black,
        );
      },
    );
  }
}

播放错误E/ExoPlayerImplInternal(30463):com.google.android.exoplayer2.ExoPlaybackException:来源错误E/ExoPlayerImplInternal(30463):登录邮箱:exoPlayer2.exoPlayerImplInternal.handleIoExceptions(外部播放器内部应用程序处理异常)(30463):电子邮件地址:(30463)在android操作系统上。处理程序。调度消息(处理程序。java:108)E/ExoPlayerImplInternal(30463):机器人操作系统。循环(循环器。java:216)E/ExoPlayerImplInternal(30463):网址android.os.HandlerThread.run处理程序线程。java:65)E/外部播放器实现内部(30463):导致原因:com.google.android.exoplayer2.source.无法识别的输入格式异常:所有可用的提取器(Mp3提取器、Flv提取器、Flac提取器、WavExtractor、FragmentedMp 4提取器、Mp4提取器、Amr提取器、PsExtractor、Ogg提取器、TsExtractor、Matroska提取器、AdtsExtractor、Ac 3提取器、Ac 4 Extractor、AviExtractor、JpegExtractor)都无法读取流。E/ExoPlayerImplInternal(30463):下载地址:com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(绑定的提取器适配器. java:92)电子版本/ExoPlayerImplInternal(30463):下载地址:谷歌官方网站:谷歌官方网站:下载地址:LoadTask.run(加载器. java:412)电子邮箱/ExoPlayerImplInternal(30463):线程池执行程序处理任务(线程池执行程序java:1187)E/ExoPlayerImplInternal(30463):运行工作器(线程池执行程序. java:1152)E/ExoPlayerImplInternal(30463):线程池执行程序$Worker.run(线程池执行程序. java:641)E/ExoPlayerImplInternal(30463):网址:java.lang.Thread.run(线程. java:784)电子音频播放器(30463):类型_来源:所有可用提取器(Mp3提取器、Flv提取器、Flac提取器、WavExtractor、FragmentedMp 4提取器、Mp4提取器、Amr提取器、PsExtractor、Ogg提取器、TsExtractor、Matroska提取器、AdtsExtractor、Ac 3提取器、Ac 4 Extractor、AviExtractor、JpegExtractor)都无法读取流。I/ExoPlayerImpl(30463):发布版本2194 ae 9 [ExoPlayerLib/2.18.1] [硬件核心、核心-AL 00、华为、28] [好的exo核心、好的exo播放器、好的exo解码器、好的exo数据源、好的exo提取器] E/抖动(30463):[错误:flutter/运行时/dart_vm_initializer.cc(41)]未处理的异常:(0)源错误E/ Flutter (30463):#0音频播放器._load(软件包:仅音频/仅音频.dart:850:9)E/ Flutter (30463):E/扑动(30463):#1音频播放器._set平台活动. set平台(软件包:just_audio/just_audio.dart:1435:28)E/ Flutter (30463):E/扑动(30463):
我想知道为什么它不起作用。

ut6juiuv

ut6juiuv1#

我对你的网址内容不太熟悉。但是,如果你是从网上检索歌曲,请使用下面的片段。

_audioPlayer = AudioPlayer.setUrl(widget.url);

如果要播放资源中的音频,请确保提供正确的路径。

相关问题