Python Forum
I can not play mp3 in pygame - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: I can not play mp3 in pygame (/thread-8132.html)



I can not play mp3 in pygame - vinicius - Feb-07-2018

import pygame
from pygame import mixer
pygame.init()
mixer.init()
mixer.music.load('21.lnk')
mixer.music.play()


RE: I can not play mp3 in pygame - Windspar - Feb-07-2018

1. Use code tags.

2. show error.

3. is 21.lnk in the same folder ?


RE: I can not play mp3 in pygame - vinicius - Feb-09-2018

yes, 21.ink in paste


RE: I can not play mp3 in pygame - metulburr - Feb-09-2018

you need a main game loop to keep the script from reaching the end of the program.

add all this after your code in the first post
done = False
song_ended = pygame.USEREVENT + 1
while not done:
    for event in pygame.event.get():
        if event.type == song_ended:
            print('The song ended')



RE: I can not play mp3 in pygame - SeabassG33 - Feb-19-2018

(Feb-09-2018, 05:13 AM)metulburr Wrote: you need a main game loop to keep the script from reaching the end of the program.

add all this after your code in the first post
done = False
song_ended = pygame.USEREVENT + 1
while not done:
    for event in pygame.event.get():
        if event.type == song_ended:
            print('The song ended')

Super useful, thanks!