pygame music, cant read mp3?

G

globalrev

http://www.pygame.org/docs/ref/mixer.html

import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2,
buffer=3072) //it complained abiout words=
so i guess its only the nbrs should be there//

pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load("example1.mp3")
pygame.mixer.music.play(loops=1, start=0.0)



Traceback (most recent call last):
File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
<module>
pygame.mixer.music.load("example1.mp3")
error: Couldn't read from 'example1.mp3'
 
D

Diez B. Roggisch

globalrev said:
http://www.pygame.org/docs/ref/mixer.html

import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2,
buffer=3072) //it complained abiout words=
so i guess its only the nbrs should be there//

pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load("example1.mp3")
pygame.mixer.music.play(loops=1, start=0.0)



Traceback (most recent call last):
File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
<module>
pygame.mixer.music.load("example1.mp3")
error: Couldn't read from 'example1.mp3'

Give it the full path to the MP3. Be aware of backward slashes + the need to
escape them.

Diez
 
G

globalrev

Give it the full path to the MP3. Be aware of backward slashes + the need to
escape them.

Diez

escape them?




import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072)
pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
pygame.mixer.music.play(loops=1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
<module>
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
error: Couldn't read from 'C:/Python25/myPrograms/pygameProgs/
example1.mp3'
 
G

globalrev

escape them?

import pygame

#pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072)
pygame.mixer.init(22050, -16, 2, 3072)
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
pygame.mixer.music.play(loops=1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\myPrograms\pygameProgs\musicexp.py", line 5, in
<module>
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
error: Couldn't read from 'C:/Python25/myPrograms/pygameProgs/
example1.mp3'

tried filenames with \ also but same result.
 
W

Wojciech Walczak

2008/5/5 said:
pygame.mixer.music.load('C:/Python25/myPrograms/pygameProgs/example1.mp3')


Are you sure that:

os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?

Check it with python.
 
G

globalrev

Are you sure that:

os.path.exists('C:/Python25/myPrograms/pygameProgs/example1.mp3') == True?

Check it with python.
False


but...it is there....
False

does it matter if i use / or \? which si recommended?
 
D

Dan Upton

False


but...it is there....

False

What about:

os.path.exists('C:\\Python25\\myPrograms\\pygameProgs\\dront.mp3') == True

That's what Diez mentioned earlier in the thread about escaping the slashes.
does it matter if i use / or \? which si recommended?


Which slash to use basically depends on whether you're on Windows
(uses \ as a path separator) or *nix (uses / as a path separator).
 
G

globalrev

False

but...it is there....


False

does it matter if i use / or \? which si recommended?

i can find .png image in the same folder and when i just change
filename from snake.png to example1.mp3 it is false.

i renamed the file once, could that have anything to do with it?
 
G

globalrev

i can find .png image in the same folder and when i just change
filename from snake.png to example1.mp3 it is false.

i renamed the file once, could that have anything to do with it?

\\ or \ or / all works.


the title of the mp3 is a long number still. i mena if i go to
properties the name is example1.mpg but the title if i go to details
is stillt he old one.
 
J

J. Cliff Dyer

\\ or \ or / all works.


the title of the mp3 is a long number still. i mena if i go to
properties the name is example1.mpg but the title if i go to details
is stillt he old one.

Now I'm confused. What is the name of the *file* on the filesystem?
You can verify this using

As for the question of \\ vs. \ vs. /: Windows will accept forward
slashes, but you may run into trouble later on down the line if windows
treats one of your forward slashes as a command line option. The native
format is to use backslashes as separators, but backslashes need to be
escaped in python's regular string literals, because of escape
sequences. Single backslashes seem to be working for you, but that's
only because you've been lucky in not having escape characters following
your backslash. Particularly, x, n, t, u, and U will cause trouble.
Probably others.

Cut'n'paste example:

$ python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
0-4: end of string in escape sequence

Notice that the \ gets doubled (escaped) automatically by python in many
of the instances, but not for the \n, and an exception gets raised for
\u (in unicode strings only), and for \x (in regular strings too). It's
safer just to escape your strings yourself. So 'C:\\foo' is always
better than 'C:\foo', even though the latter may sometimes work. Better
still is to create a list of directories, and use os.path.join(dirlist)
as follows:

directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
os.path.join(directory)

Then python can worry about the gritty details, and you don't have to.
 
D

Diez B. Roggisch

directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
os.path.join(directory)

Then python can worry about the gritty details, and you don't have to.

Or somewhat neater IMHO:


os.path.join('C:','Python25','myPrograms','pygameProgs','dront.mp3')

Diez
 
G

globalrev

directory = ['C:','Python25','myPrograms','pygameProgs','dront.mp3']
os.path.join(directory)
Then python can worry about the gritty details, and you don't have to.

Or somewhat neater IMHO:

os.path.join('C:','Python25','myPrograms','pygameProgs','dront.mp3')

Diez

ty i solved it now, apparenly renaming a file it still has its native
filename...

it plays now when i run it from the shell but from the command line it
just blips and finishes right away.

also the sound is not very good, it is disturbed at some parts, why is
this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top