why am i havng this error Exception has occurred. FlutterError (Unable to load asset: "assets/assets/audio/ontheroad.mp3". The asset does not exist or has empty data.)
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:musica/models/song.dart';
class PlaylistProvider extends ChangeNotifier {
//playlist of songs
final List<Song> _playlist = [
Song(
songName: "Hollywoods Bleeding",
artistName: "Post Malone",
albumArtImagePath: "assets/image/posty.jpg",
audioPath: "assets/audio/bleeding.mp3",
),
Song(
songName: "Ghetto christmas",
artistName: "Xxxtentacion",
albumArtImagePath: "assets/image/x2.jpg",
audioPath: "assets/audio/ghetto.mp3",
),
Song(
songName: "On the road",
artistName: "Post Malone",
albumArtImagePath: "assets/image/posty3.jpg",
audioPath: "assets/audio/ontheroad.mp3",
),
Song(
songName: "Sad!",
artistName: "Xxxtentacion",
albumArtImagePath: "assets/image/x.jpg",
audioPath: "assets/audio/sad.mp3",
),
];
int? _currentSongIndex;
//audio player
final AudioPlayer _audioPlayer = AudioPlayer();
//duration
Duration _currentDuration = Duration.zero;
Duration _totalDuration = Duration.zero;
//constructor
PlaylistProvider() {
listenToDuration();
}
//initially not playing
bool _isPlaying = false;
//play the song
void play() async {
final String path = _playlist[_currentSongIndex!].audioPath;
await _audioPlayer.stop(); //stop current song
await _audioPlayer.play(AssetSource(path)); //why am i getting errors ?
_isPlaying = true;
notifyListeners();
}
so i am having issue on the await await _audioPlayer.play(AssetSource(path)); //why am i getting errors ? can anyone help me out
its not leading the song in my music player app
assets:
- assets/audio/
- assets/image/
_playlist: This private variable holds a list of Song objects representing the playlist.
_currentSongIndex: Another private variable to store the index of the currently playing song in the playlist.
_audioPlayer: An instance of the AudioPlayer class used for playing audio files.
_currentDuration: Tracks the current playback position of the song.
_totalDuration: Stores the total duration of the currently playing song.
PlaylistProvider(): The constructor likely initializes some values or sets up listeners.
_isPlaying: A boolean flag indicating whether the music is currently playing.
play(): This function takes care of playing a song. It retrieves the path from the current song in the playlist, stops any currently playing song, starts playing the new song using AssetSource, updates the playing state, and notifies listeners about changes.
1