I am making a music player with flutter so, I wanna to ask how to access all the files of a particular extension ( mp3, wav ) with it’s details in Flutter or if not in Flutter then Python to play those music files with details like song name, author name
Advertisement
Answer
In python, you can basically do:
import os files=os.listdir("/path/to/folder or empty for working folder") for file in files: if file.endswith("extension but for you .mp3/wav"): print(file)
By doing this you can get the file name with .mp3/wav
extension.
Otherwise you can use glob
library:
import glob for file in glob.glob("*.mp3 or /path/*.mp3"): print(file)
By using glob
also output is same!
For getting artists and other metadata you can use songdetails
library:
import glob import songdetails for file in glob.glob("*.mp3 or /path/*.mp3"): song = songdetails.scan(file) if song is not None: print(song) print(song.artist) print(song.duration)
For more information visit songdetails github page.
If this answer helps you to solve your problem then, don’t forget to mark this as accepted answer.