Reputation: 13
i have given every permisson but its not working
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,
);
},
);
}
}
Playback error E/ExoPlayerImplInternal(30463): com.google.android.exoplayer2.ExoPlaybackException: Source error E/ExoPlayerImplInternal(30463): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:632) E/ExoPlayerImplInternal(30463): at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:602) E/ExoPlayerImplInternal(30463): at android.os.Handler.dispatchMessage(Handler.java:108) E/ExoPlayerImplInternal(30463): at android.os.Looper.loop(Looper.java:216) E/ExoPlayerImplInternal(30463): at android.os.HandlerThread.run(HandlerThread.java:65) E/ExoPlayerImplInternal(30463): Caused by: com.google.android.exoplayer2.source.UnrecognizedInputFormatException: None of the available extractors (Mp3Extractor, FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, AviExtractor, JpegExtractor) could read the stream. E/ExoPlayerImplInternal(30463): at com.google.android.exoplayer2.source.BundledExtractorsAdapter.init(BundledExtractorsAdapter.java:92) E/ExoPlayerImplInternal(30463): at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1017) E/ExoPlayerImplInternal(30463): at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412) E/ExoPlayerImplInternal(30463): at java.util.concurrent.ThreadPoolExecutor.processTask(ThreadPoolExecutor.java:1187) E/ExoPlayerImplInternal(30463): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152) E/ExoPlayerImplInternal(30463): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/ExoPlayerImplInternal(30463): at java.lang.Thread.run(Thread.java:784) E/AudioPlayer(30463): TYPE_SOURCE: None of the available extractors (Mp3Extractor, FlvExtractor, FlacExtractor, WavExtractor, FragmentedMp4Extractor, Mp4Extractor, AmrExtractor, PsExtractor, OggExtractor, TsExtractor, MatroskaExtractor, AdtsExtractor, Ac3Extractor, Ac4Extractor, AviExtractor, JpegExtractor) could read the stream. I/ExoPlayerImpl(30463): Release 2194ae9 [ExoPlayerLib/2.18.1] [HWCOR, COR-AL00, HUAWEI, 28] [goog.exo.core, goog.exo.exoplayer, goog.exo.decoder, goog.exo.datasource, goog.exo.extractor] E/flutter (30463): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: (0) Source error E/flutter (30463): #0 AudioPlayer._load (package:just_audio/just_audio.dart:850:9) E/flutter (30463): E/flutter (30463): #1 AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1435:28) E/flutter (30463): E/flutter (30463):
I need to know why it is not working.
Upvotes: 0
Views: 563
Reputation: 184
I'm not familiar with the content of your URL. However, if you are retrieving a song from an online source, use the snippet below.
_audioPlayer = AudioPlayer.setUrl(widget.url);
If you want to play audio from assets, make sure you provide the correct path.
Upvotes: -1