Cant load music into pygame

2024/10/5 19:19:39

please help if you can. Can't seem to be able to upload music into my game in progress. It comes up with the error of "can't load"... Would be great if someone got back to me quick, This is a major work due in 1 week

import sys, random, pygame, time
from pygame.locals import *
pygame.init()screen = pygame.display.set_mode((600,500))
pygame.display.set_caption("game")
myfont = pygame.font.SysFont("cambria", 19)
myfont2 = pygame.font.SysFont("cambria", 45)
myfont3 = pygame.font.SysFont("cambria", 30)#musicpygame.mixer.music.load('sddmusic.mp3')
pygame.mixer.music.play(0)def print_text(font, x, y, text, color):imgText = font.render(text, True, color)screen.blit(imgText, (x,y))game = False
white = 255,255,255mouse_down_x = mouse_down_y = 0
mouse_down = 0
while True:for event in pygame.event.get():if event.type == QUIT:pygame.quit()sys.exit()elif event.type == MOUSEBUTTONDOWN:mouse_down = event.buttonmouse_down_x, mouse_down_y = event.posscreen.fill((85,107,47))#print_text(myfont,0,0, str(mouse_down), white)#print_text(myfont,0,15, str(mouse_down_x), white)#print_text(myfont,0,30, str(mouse_down_y), white) if game == True:pygame.draw.line(screen, white, (100,0), (100,600), 20)pygame.draw.line(screen, white, (500,0), (500,600), 20)time_get = time.clock() - time_startif time_get > 1:print_text(myfont, 240,0 ,"Hello?", (255,255,255))if time_get > 1.75:print_text(myfont, 240,50, "Commander?", (255,255,255))if time_get > 2.2:print_text(myfont, 240,100, "Do you copy?",(255,255,255))else:pygame.draw.rect(screen, white,(204,176,200,40),2)print_text(myfont2, 100, 100,"Operation L.A.U.N.C.H", (255,255,255))print_text(myfont3,270,176, "Start", white)pygame.draw.rect(screen, white,(204,280,200,40),2)print_text(myfont3,270,280, "Quit", white)if mouse_down == 1 and mouse_down_x > 204 and mouse_down_y > 176 and mouse_down_x < 404 and mouse_down_y < 216:game = Truemouse_down = 0mouse_down_x = 0mouse_down_y = 0time_start = time.clock()if mouse_down == 1 and mouse_down_x > 204 and mouse_down_y > 280 and mouse_down_x < 404 and mouse_down_y < 320:pygame.quit()sys.exit()pygame.display.update()
Answer

I guess your problem is due to the following reason:
1)Go go to file > save as (shortcut : Ctrl+Shift+S) and try saving the python file in the same address in which your music is stored.

Suggestion:
Try converting the mp3 to wav.It works better.

https://en.xdnf.cn/q/119542.html

Related Q&A

C# Socket: how to keep it open?

I am creating a simple server (C#) and client (python) that communicate using sockets. The server create a var listener = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp)then …

Python Selenium - how to get confirmation after submit

I have a follow up question on this post, I want to get any confirmation text after I hit submit button. Either the code works or not. html - invalid example <div class="serialModalArea js-seri…

Assigning a input on a line to its line number?

I was having a go at the following problem from the AIO (Australian Informatics Olympiad) Training Problems Site (Question in Italics and specifics in bold, my attempt below): The Problem Encyclopaedia…

Create a new list according to item value

I have a list like below. [T46, T43, R45, R44, B46, B43, L45, L44, C46, C45]where I want to group according to int value:[id][ , , , , ] # AREA PATTERN [Top, Right, Bottom, Left, Center][46][1,0,1…

Concatenating many time and date columns

I have many date and time column pairs (around 15 each) that share the same prefix, ie. SH or DEL. The columns are all of dtype object, ie. string. All the columns belong to the same Dataframe. Here is…

Python with ICS files and CSV [duplicate]

This question already has answers here:Parsing files (ics/ icalendar) using Python(6 answers)Closed 5 years ago.one friend ask me some help on a personnal project, but I have to admit my skills in Pyth…

loading my data in numpy genfromtxt get errors

I have my data file contain 7500 lines with :Y1C 1.53 -0.06 0.58 0.52 0.42 0.16 0.79 -0.6 -0.3 -0.78 -0.14 0.38 0.34 0.23 0.26 -1.8 -0.1 -0.17 0.3…

Install dlib with cuda support ubuntu 18.04

I have CUDA 9.0 and CUDNN 7.1 installed on Ubuntu 18.04(Linux mint 19). Tensorflow-gpu works fine on GPU(GTX 1080ti).Now i am trying to build dlib with CUDA support:sudo python3 setup.py install --yes …

View 3 dimensional Numpy array in Matplotlib and taking arguments from Keyboard or mouse

I have 3 dimensional data say (5,100,100). Now I would like to see them slice by slice upon hitting the down arrow button.

python default argument syntax error

I just wrote a small text class in python for a game written using pygame and for some reason my default arguments arent working. I tried looking at the python documentation to see if that might give m…