473,739 Members | 5,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pygame music, cant read mp3?

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

import pygame

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

pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load("examp le1.mp3")
pygame.mixer.mu sic.play(loops= 1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.load("examp le1.mp3")
error: Couldn't read from 'example1.mp3'
Jun 27 '08 #1
11 11678
globalrev wrote:
http://www.pygame.org/docs/ref/mixer.html

import pygame

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

pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load("examp le1.mp3")
pygame.mixer.mu sic.play(loops= 1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.load("examp le1.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.w eb.dewrote:
globalrev wrote:
http://www.pygame.org/docs/ref/mixer.html
import pygame
#pygame.mixer.i nit(frequency=2 2050, size=-16, channels=2,
buffer=3072) //it complained abiout words=
so i guess its only the nbrs should be there//
pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load("examp le1.mp3")
pygame.mixer.mu sic.play(loops= 1, start=0.0)
Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.load("examp le1.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.i nit(frequency=2 2050, size=-16, channels=2, buffer=3072)
pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
pygame.mixer.mu sic.play(loops= 1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.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...@yaho o.sewrote:
On 5 Maj, 13:47, "Diez B. Roggisch" <de...@nospam.w eb.dewrote:
globalrev wrote:
>http://www.pygame.org/docs/ref/mixer.html
import pygame
#pygame.mixer.i nit(frequency=2 2050, size=-16, channels=2,
buffer=3072) //it complained abiout words=
so i guess its only the nbrs should be there//
pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load("examp le1.mp3")
pygame.mixer.mu sic.play(loops= 1, start=0.0)
Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.load("examp le1.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.i nit(frequency=2 2050, size=-16, channels=2, buffer=3072)
pygame.mixer.in it(22050, -16, 2, 3072)
pygame.mixer.mu sic.load('C:/Python25/myPrograms/pygameProgs/
example1.mp3')
pygame.mixer.mu sic.play(loops= 1, start=0.0)

Traceback (most recent call last):
File "C:\Python25\my Programs\pygame Progs\musicexp. py", line 5, in
<module>
pygame.mixer.mu sic.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*******@yaho o.se>:
pygame.mixer.mu sic.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...@yaho o.se>:
pygame.mixer.mu sic.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.exist s('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exist s('C:\Python25\ myPrograms\pyga meProgs\dront.m p3') == 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*******@yaho o.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick .walc...@gmail. com>
wrote:
2008/5/5, globalrev <skanem...@yaho o.se>:
pygame.mixer.mu sic.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.exist s('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exist s('C:\Python25\ myPrograms\pyga meProgs\dront.m p3') == True
False
What about:

os.path.exists( 'C:\\Python25\\ myPrograms\\pyg ameProgs\\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...@yaho o.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick .walc...@gmail. com>
wrote:
2008/5/5, globalrev <skanem...@yaho o.se>:
pygame.mixer.mu sic.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\m yPrograms\pygam eProgs\dront.mp 3') == 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...@yaho o.sewrote:
On 5 Maj, 16:09, globalrev <skanem...@yaho o.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick .walc...@gmail. com>
wrote:
2008/5/5, globalrev <skanem...@yaho o.se>:
pygame.mixer.mu sic.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.exist s('C:/Python25/myPrograms/pygameProgs/dront.mp3') == True
False
but...it is there....
>>os.path.exist s('C:\Python25\ myPrograms\pyga meProgs\dront.m p3') == 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...@yaho o.sewrote:
On 5 Maj, 16:09, globalrev <skanem...@yaho o.sewrote:
On 5 Maj, 14:17, "Wojciech Walczak" <wojtek.gminick .walc...@gmail. com>
wrote:
2008/5/5, globalrev <skanem...@yaho o.se>:
pygame.mixer.mu sic.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\m yPrograms\pygam eProgs\dront.mp 3') == 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'
UnicodeDecodeEr ror: '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(di rlist)
as follows:

directory = ['C:','Python25' ,'myPrograms',' pygameProgs','d ront.mp3']
os.path.join(di rectory)

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

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

Similar topics

12
16137
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", pygame.mixer.get_num_channels() pygame.mixer.music.set_volume(1.0) pygame.mixer.music.load('file1.mp3)
1
1636
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 possible? If not, do you know an other python music lib that do that? Thanks a lot
3
3720
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 Pygame to manage the image window, as it was the easiest way to implement the functionality I needed. The surrounding interface windows (there are two) are constructed with Tkinter. Despite their unholy union, Pygame and Tkinter seem, generally,...
0
2165
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 --http://mail.google.com/mail/?realattid=f_3n2tmv&attid=0.1&disp=inline&view=att&th=10f0d56e8cb478be 24 oct 2006
10
2081
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 wxGlade 0.5 on Sat Oct 27 15:46:36 2007 import wx, os, pygame pygame.init() class MyFrame2(wx.MDIChildFrame):
1
5847
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 coding this in Eclipse ----------------------------------------- My music files are: D:\My Documents\School Work\Comp 523\Projects\MediaPlayer\MediaPlayer\src\MediaPlayer\Music\one.mp3 ----------------------------------------- My Project files...
1
2358
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", line 3, in <module> pygame.mixer.music.load(example1.mp3)
5
3031
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() screen.fill(screencolor) pygame.draw.circle(screen, linecolor, (500, 20), 12, 0)
0
1123
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 functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. Pygame is highly portable and runs on nearly
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9266
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9209
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8215
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6054
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.