Я пытаюсь воспроизвести звук в своем коде, но он создает ошибку и работает неправильно.
Ошибка: невозможно найти запись каталога в pubspec.yaml: D:\Flutter\Newfolder\practice\audio
E/flutter (10832): [ОШИБКА:flutter/runtime/dart_vm_initializer.cc(41)] Необработанное исключение: невозможно загрузить актив: «активы/активы/аудио/sound_alarm.mp3». E/futter (10832): актив не существует или имеет пустые данные. E/futter (10832): #0
PlatformAssetBundle.load. (пакет: flutter/src/services/asset_bundle.dart:254:9) E/flutter (10832): E/flutter (10832): #1
AudioCache.fetchToMemory (пакет:audioplayers/src/audio_cache.dart:92:22) E/flutter (10832): E/flutter (10832): #2 AudioCache.load (пакет:audioplayers/src/audio_cache.dart:118:31) E/flutter (10832): E/flutter (10832): # 3
AudioPlayer.setSourceAsset (пакет:audioplayers/src/audioplayer.dart:310:17) E/flutter (10832): E/flutter (10832): #4 _Page2State.play(package:practice/page.dart:166:5) ) Э/трепетание (10832):
import 'dart:ffi';
import 'package:audio_service/audio_service.dart';
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:just_audio/just_audio.dart' as audio;
class Page2 extends StatefulWidget {
Page2({Key? key}) : super(key: key);
@override
State<Page2> createState() => _Page2State();
}
class _Page2State extends State<Page2> {
static AudioPlayer player = AudioPlayer();
@override
void initState() {
// TODO: implement initState
// late Source audioUrl = UrlSource('https://www.jiosaavn.com/album/tu-jhoothi-main-makkaar/Zk6,htMIngg_');
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Audio'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: () {
// final player = AudioPlayer();
// player.play(audioUrl);
play();
},
icon: Icon(Icons.play_arrow),
),
],
),
),
);
}
play() async {
await player.setSourceAsset('assets/audio/sound_alarm.mp3');
player.play(
AssetSource('assets/audio/sound_alarm.mp3'),
);
}
}
Pubspec.yml
assets:
- audio/