Pygame music not playing
I'm trying to make a text adventure game, and I want it so that whenever you win a fight it plays a little fanfare. I am using pygame, and it works with all of my other music except this one. Here's the code:
print(("-"*25)+"Victory!"+("-"*25))
pygame.init()
pygame.mixer.music.load('Victory.mp3')
pygame.mixer.music.play(0, 0.0)
This code is the exact same as all of the other times, but for some reason this time it doesn't work. The Victory.mp3 is only a few seconds long, while the others are much longer. Could this have something to do with it?
python pygame playback
add a comment |
I'm trying to make a text adventure game, and I want it so that whenever you win a fight it plays a little fanfare. I am using pygame, and it works with all of my other music except this one. Here's the code:
print(("-"*25)+"Victory!"+("-"*25))
pygame.init()
pygame.mixer.music.load('Victory.mp3')
pygame.mixer.music.play(0, 0.0)
This code is the exact same as all of the other times, but for some reason this time it doesn't work. The Victory.mp3 is only a few seconds long, while the others are much longer. Could this have something to do with it?
python pygame playback
I think the question is close-to-impossible to answer, since we don't have enough information. Can you trypygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.
– dyukha
Dec 4 '18 at 1:50
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try addingpygame.event.wait()
afterplay
.
– dyukha
Dec 5 '18 at 2:44
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00
add a comment |
I'm trying to make a text adventure game, and I want it so that whenever you win a fight it plays a little fanfare. I am using pygame, and it works with all of my other music except this one. Here's the code:
print(("-"*25)+"Victory!"+("-"*25))
pygame.init()
pygame.mixer.music.load('Victory.mp3')
pygame.mixer.music.play(0, 0.0)
This code is the exact same as all of the other times, but for some reason this time it doesn't work. The Victory.mp3 is only a few seconds long, while the others are much longer. Could this have something to do with it?
python pygame playback
I'm trying to make a text adventure game, and I want it so that whenever you win a fight it plays a little fanfare. I am using pygame, and it works with all of my other music except this one. Here's the code:
print(("-"*25)+"Victory!"+("-"*25))
pygame.init()
pygame.mixer.music.load('Victory.mp3')
pygame.mixer.music.play(0, 0.0)
This code is the exact same as all of the other times, but for some reason this time it doesn't work. The Victory.mp3 is only a few seconds long, while the others are much longer. Could this have something to do with it?
python pygame playback
python pygame playback
edited Jan 1 at 0:50
jpyams
1,3551233
1,3551233
asked Nov 23 '18 at 1:25
Justin GawronJustin Gawron
12
12
I think the question is close-to-impossible to answer, since we don't have enough information. Can you trypygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.
– dyukha
Dec 4 '18 at 1:50
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try addingpygame.event.wait()
afterplay
.
– dyukha
Dec 5 '18 at 2:44
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00
add a comment |
I think the question is close-to-impossible to answer, since we don't have enough information. Can you trypygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.
– dyukha
Dec 4 '18 at 1:50
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try addingpygame.event.wait()
afterplay
.
– dyukha
Dec 5 '18 at 2:44
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00
I think the question is close-to-impossible to answer, since we don't have enough information. Can you try
pygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.– dyukha
Dec 4 '18 at 1:50
I think the question is close-to-impossible to answer, since we don't have enough information. Can you try
pygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.– dyukha
Dec 4 '18 at 1:50
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try adding
pygame.event.wait()
after play
.– dyukha
Dec 5 '18 at 2:44
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try adding
pygame.event.wait()
after play
.– dyukha
Dec 5 '18 at 2:44
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439659%2fpygame-music-not-playing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53439659%2fpygame-music-not-playing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think the question is close-to-impossible to answer, since we don't have enough information. Can you try
pygame.mixer.music.play(-1, 0.0)
? It should play the music infinitely many times. I believe you've already tested that the file indeed contains the music you expect.– dyukha
Dec 4 '18 at 1:50
Does your program end right after that command? I guess it also can be a reason.
– dyukha
Dec 4 '18 at 1:54
The program doesn't end after there, after it prints the victory statement it calls a function which asks a yes or no question. I tried using (-1, 0.0) instead of (0, 0.0) and it did loop infinitely. I can't seem to get it to play just once, though.
– Justin Gawron
Dec 5 '18 at 2:24
Are you sure your other music is played correctly? Is it possible that all your music has few seconds of it cut? You can also try adding
pygame.event.wait()
afterplay
.– dyukha
Dec 5 '18 at 2:44
I just ran the game again, I didn't change anything but the music worked now. It was probably just a temporary glitch. Thanks for your help!
– Justin Gawron
Dec 6 '18 at 18:00