0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Flutterでローカルにある効果音を再生する

Last updated at Posted at 2023-04-22

ボタンをクリックした場合などの効果音をFlutterで再生する方法です。

audiocacheの方法やjust_audioなどあっちこっち探し回った結果、一番シンプルなaudioplayersの方法にたどり着きました。

  • audiocacheは執筆時点(2023/4/22)で廃止されたようです。

手順

pubspec.yaml
dependencies:
  audioplayers:  #この行をdependenciesに追加

ディレクトリ構成

root/
├ assets
  ├ sounds
    ├ audio.mp3

sample.dart
//再生するファイルのトップにimport文を追加
import 'package:audioplayers/audioplayers.dart';

//再生したいところで以下を実行
final player = AudioPlayer();
player.play(AssetSource('sounds/audio.mp3'));

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?