반응형
패키지 정보
- 터미널 설치
flutter pub add assets_audio_player
- pubspec.yaml 설정
flutter:
assets:
- assets/audios/
- 코드 작성
import 'package:assets_audio_player/assets_audio_player.dart';
import 'package:flutter/material.dart';
late AssetsAudioPlayer _assetsAudioPlayer = AssetsAudioPlayer.newPlayer();
class ExamplePage extends StatefulWidget {
const ExamplePage({Key? key}) : super(key: key);
@override
State<ExamplePage> createState() => _ExamplePageState();
}
class _ExamplePageState extends State<ExamplePage> {
@override
void initState() {
super.initState();
_assetsAudioPlayer.open(
Audio("assets/audios/Background.mp3"),
loopMode: LoopMode.single, //반복 여부 (LoopMode.none : 없음)
autoStart: false, //자동 시작 여부
showNotification: false, //스마트폰 알림 창에 띄울지 여부
);
_assetsAudioPlayer.play(); //재생
_assetsAudioPlayer.pause(); //멈춤
_assetsAudioPlayer.stop(); //정지
}
반응형