【问题标题】:flutter audioplayers plugin don't play sound instead freezes the app颤动的音频播放器插件不播放声音而是冻结应用程序
【发布时间】:2020-11-15 00:22:44
【问题描述】:

我正在使用flutter插件audioplayers: ^0.15.1,下面的代码在Android中工作,但在IOS中不工作,而不是冻结应用程序。

我在 ios 模拟器中运行代码并单击按钮。它假设播放 mp3 文件,但根本没有声音。应用程序被冻结。 assets_audio_player 插件也有同样的问题。

请帮忙解决这个问题。

import 'package:flutter/material.dart';
import 'package:audioplayers/audio_cache.dart';

void main() => runApp(XylophoneApp());

class XylophoneApp extends StatelessWidget {
  void playNote(int noteNO) {
    final player = AudioCache();
    player.play('note$noteNO.wav');
  }

  Expanded buildKey(int no, Color color) {
    return Expanded(
      child: FlatButton(
        color: color,
        onPressed: () {
          playNote(no);
        },
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.black,
        body: SafeArea(
          child: Center(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                buildKey(1,Colors.red),
                buildKey(2,Colors.orange),
                buildKey(3,Colors.yellow),
                buildKey(4,Colors.green),
                buildKey(5,Colors.blue),
                buildKey(6,Colors.indigo),
                buildKey(7,Colors.purple),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

void playNote(int noteNO) {
  final player = AudioCache();
  player.play('note$noteNO.wav');
}

调试控制台:Screenshot

iOS => call startHeadlessService, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
iOS => call play, playerId 6178a81e-22dc-485b-bfc8-f6a8402f518e
play!
isLocal: 1 1
volume: 1.000000 1
position: 0 (null)
setUrl /Users/akshay/Library/Developer/CoreSimulator/Devices/575F03D0-0EBE-4813-970A-14128CEF49ED/data/Containers/Data/Application/394C51F0-1ABD-4315-921A-F92E97CC1F98/Library/Caches/note5.wav
[VERBOSE-2:profiler_metrics_ios.mm(184)] Error retrieving thread information: (ipc/send) invalid destination port
player status: 2
player status: 2
player status: 2

【问题讨论】:

    标签: ios flutter audio plugins ios-simulator


    【解决方案1】:

    由于您使用的是 ^,它会将您升级到 0.16.x(主要版本号为 0 的最新版本)

    很可能您安装了最新可用的音频播放器包 (0.16.0),它们存在导致应用程序在 iOS 设备上崩溃的问题https://github.com/luanpotter/audioplayers/issues/613 您可以在 pubspec.yaml 中简单地降级到 0.15.1(删除 ^)并运行 packages get 命令使其工作

    【讨论】:

      【解决方案2】:

      更改 pubspec.yaml 文件。

      audioplayers:
          git:
            url: git://github.com/luanpotter/audioplayers.git
      

      【讨论】:

        猜你喜欢
        • 2022-08-21
        • 2022-08-23
        • 1970-01-01
        • 2019-03-18
        • 1970-01-01
        • 1970-01-01
        • 2014-06-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多