473,238 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

pygame music, cant read mp3?

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.p y", line 5, in
<module>
pygame.mixer.music.load("example1.mp3")
error: Couldn't read from 'example1.mp3'
Jun 27 '08 #1
11 11616
globalrev wrote:
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.p y", 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
Jun 27 '08 #2
On 5 Maj, 13:47, "Diez B. Roggisch" <de...@nospam.web.dewrote:
globalrev wrote:
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.p y", 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
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.p y", 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'
Jun 27 '08 #3
On 5 Maj, 14:03, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 13:47, "Diez B. Roggisch" <de...@nospam.web.dewrote:
globalrev wrote:
>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.p y", 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

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.p y", 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.
Jun 27 '08 #4
2008/5/5, globalrev <sk*******@yahoo.se>:
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.

--
Regards,
Wojtek Walczak
http://www.stud.umk.pl/~wojtekwa/
Jun 27 '08 #5
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@gmail.com>
wrote:
2008/5/5, globalrev <skanem...@yahoo.se>:
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.

--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>>import os
os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exists('C:\Python25\myPrograms\pygamePro gs\dront.mp3') == True
False

does it matter if i use / or \? which si recommended?
Jun 27 '08 #6
On Mon, May 5, 2008 at 10:09 AM, globalrev <sk*******@yahoo.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@gmail.com>
wrote:
2008/5/5, globalrev <skanem...@yahoo.se>:
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.
>
--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/

>>import os
>>os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exists('C:\Python25\myPrograms\pygamePro gs\dront.mp3') == True
False
What about:

os.path.exists('C:\\Python25\\myPrograms\\pygamePr ogs\\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).
Jun 27 '08 #7
On 5 Maj, 16:09, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@gmail.com>
wrote:
2008/5/5, globalrev <skanem...@yahoo.se>:
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.
--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>import os
os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True

False

but...it is there....
>os.path.exists('C:\Python25\myPrograms\pygameProg s\dront.mp3') == True

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?
Jun 27 '08 #8
On 5 Maj, 16:29, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 16:09, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@gmail.com>
wrote:
2008/5/5, globalrev <skanem...@yahoo.se>:
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.
--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>>import os
>>os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exists('C:\Python25\myPrograms\pygamePro gs\dront.mp3') == True
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?
\\ 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.
Jun 27 '08 #9
On Mon, 2008-05-05 at 07:32 -0700, globalrev wrote:
On 5 Maj, 16:29, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 16:09, globalrev <skanem...@yahoo.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick.walc...@gmail.com>
wrote:
2008/5/5, globalrev <skanem...@yahoo.se>:
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.
--
Regards,
Wojtek Walczakhttp://www.stud.umk.pl/~wojtekwa/
>import os
>os.path.exists('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>os.path.exists('C:\Python25\myPrograms\pygameProg s\dront.mp3') == True
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?

\\ 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
>>os.listdir('C:/Python25/myPrograms/pygameProgs')
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.
>>'\efoo'
'\\efoo'
>>'\dfoo'
'\\dfoo'
>>'\ufoo'
'\\ufoo'
>>'\uabcd'
'\\uabcd'
>>u'\uabcd'
u'\uabcd'
>>u'\ufoo'
UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
0-4: end of string in escape sequence
>>'\xfoo'
ValueError: invalid \x escape
>>'\nfoo'
'\nfoo'
>>print '\nfoo'
foo
>>>
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.

--
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill

Jun 27 '08 #10
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','pygameP rogs','dront.mp3')

Diez
Jun 27 '08 #11
On 5 Maj, 17:25, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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','pygameP rogs','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?
Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Marian Aldenhövel | last post by:
Hi, I am trying to make pygame play music on windows. This simple program: import pygame,time pygame.init() print "Mixer settings", pygame.mixer.get_init() print "Mixer channels",...
1
by: maxime | last post by:
Hi, I try to develop a game in python and pygame. In my game I play a music (.mid with pygame.mixer.music) but sometime I need to accelerate it but I don't see how to do that with pygame. Is it...
3
by: Tim Knauf | last post by:
Hi everyone, I'm glad to have found this list. I've written a small script for my own use which, amongst other things, captures mouse click information from a window containing an image. I used...
0
by: U S Contractors Offering Service A Non-profit | last post by:
This Sunday the 26th 2006 there will be Music @ Tue Nov Inbox Reply Craig Somerford to me show details 9:54 pm (26 minutes ago) #1St "CLICK" HeAt frOm A blanket...
10
by: exodus | last post by:
As a fun little task to gain more knowledge of python, i decided to try to mimick the ipod UI with it. here's what i've got so far #!/usr/bin/env python # -*- coding: utf-8 -*- # generated by...
1
by: zswartz | last post by:
Hi All, I've been stuck here for some time now and can't figure this out. If ANYONE can assist me, that would be AMAZING!! I have Windows XP, with Python 25 and Pygame for python 25. I am also...
1
by: globalrev | last post by:
import pygame 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",...
5
by: defn noob | last post by:
Im using PyGame to draw images of graphs and trees. Howver right now i am looping using: while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() ...
0
by: illume | last post by:
Hello, Stick a fork in it, it's baked... nice and toasty. A new version of pygame is out. http://www.pygame.org/ Pygame is a set of Python modules designed for writing games. Pygame adds...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.