+ 1
Python Music Player
I'm trying to make a music player in Python, but every time I run the program nothing plays. Can someone please tell me what I'm doing wrong? EDIT: I'm running this in VS Code https://code.sololearn.com/cg0zPq6GECPT/?ref=app
11 odpowiedzi
+ 2
ﹺ ﹺ
he said he runned this on VS Code not sololearn, you should read the questions first.
i used to play with pygame back in the days, let me open my dusty old files again.
+ 2
so i've checked out my old music projects and the problem with your code is on the file path.
i don't know what OS you're using
if you're using windows the file path should use a backslash(\)
however on mac and linux it's (/)
and python basically reads slashes as an escape character, not as a character so if you try
to print('\n') the slash and n wouldn't get printed and you get a newline instead. to overcome this you should change '\' into '\\' to cancel the escape character.
so copy pasting the file path wouldn't make python able to read your files. you need to cancel out the escape characters first.
so the buggy code should instead be
mixer.music.load('C://Users//John Boland//Desktop//Code//VS Code//Python//Test_Codes//Fódlan Winds - FE Three Houses.mp3')
i personally do not use this method since this is not an elegant way of using file paths
if you're interested to use a better way of doing file paths then i recommend using the os.path.join() method
+ 1
Code Babylon yes, you can also copy the music file path and paste it on your program to instantly get the file path.
+ 1
lvl 1 crook
I tried both \\ and // just now and neither played the audio.
+ 1
class MusicPlayer {
private var songs: Array<String> = arrayOf()
//your code goes here
fun add(song:String):Array<String> {
songs += song
return songs
}
fun show() {
for (song in songs) {
println(song)
}
}
fun play() {
println ("Playing " + songs[0])
}
}
fun main(args: Array<String>) {
val m = MusicPlayer()
while(true) {
var input = readLine()!!.toString()
if(input == "stop") {
break
}
m.add(input)
}
m.show()
m.play()
}
0
lvl 1 crook I'm running this on Windows, so I use "\" correct?
0
lvl 1 crook Just to clarify, I double \\?
0
why don't you try them and see how it does
0
pygame doesn’t work for python sololearn console
0
Copy this answer and check correct answer and like thank you