Answer the question
In order to leave comments, you need to log in
How to queue up music in Pygame Mixer?
main.py
import eel
from pygame import mixer
mixer.init()
eel.init('web')
paused = False
@eel.expose
def play_music(x):
global paused
if paused:
mixer.music.unpause()
paused = False
else:
mixer.music.load(x)
mixer.music.play(-1)
@eel.expose
def queue_music(x):
mixer.music.queue(x)
@eel.expose
def stop_music():
print("Music Stopped")
mixer.music.stop()
@eel.expose
def pause_music():
global paused
paused = True
mixer.music.pause()
eel.start('main.html', size=(999, 999))
<!DOCTYPE html>
<html>
<head>
<title>Cloudy</title>
<link rel="icon" href="images/favicon.png" type="image/png" sizes="16x16">
<link rel="stylesheet" href="styles.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<!-- Include eel.js - note this file doesn't exist in the 'web' directory -->
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript">
$(function(){
$("#play").click(function(){
eel.play_music($("#inp").val());
$('#inp').val('');
});
$("#queue").click(function(){
eel.queue_music($("#inp").val());
$('#inp').val('');
});
$("#stop").click(function(){
eel.stop_music();
});
$("#pause").click(function(){
eel.pause_music();
});
});
</script>
</head>
<body>
<div>
<h2>MP3 & WAV player</h2>
<input type='text' id="inp" placeholder='Enter the path to the file . . .' value="Я-женюсь-на-девочке-из-аниме.wav">
<input type='button' class="default" id="play" style="background: blue" value='Play'>
<input type='button' class="default" id="stop" style="background: red;" value='Stop'>
<input type='button' class="default" id="pause" style="background: green;" value='Pause'>
<input type='button' class="default" id="queue" style="background: orange;" value='Queue'>
</div>
</body>
</html>
* {
font-family: "Arial";
}
body {
background: #000;
color: #FFF;
}
input {
background: white;
border-radius: 1px;
width: 100%;
padding: 20px;
color: black;
outline: none;
border: none;
display: block;
font-size: 20px;
}
input::placeholder {
color: rgba(0, 0, 0, .5);
}
input[type=text],
input[type=password] {
box-sizing : border-box;
}
.default {
width: 100%;
border-radius: 1px;
margin-top: 10px;
padding: 20px;
color: white;
outline: none;
font-size: 20px;
text-transform: uppercase;
float: left;
}
.default:hover {
opacity: .9;
}
Answer the question
In order to leave comments, you need to log in
No need, thanks! I figured it out myself, remade main.py to:
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import eel
from pygame import mixer
import time
mixer.init()
eel.init('web')
paused = False
queue = False
next_song = None
@eel.expose
def play_music(x):
global paused, queue
if paused:
mixer.music.unpause()
paused = False
elif queue:
mixer.music.load(next_song)
mixer.music.play()
queue = False
else:
mixer.music.load(x)
mixer.music.play()
@eel.expose
def queue_music(x):
global queue, next_song
next_song = x
queue = True
print("Next Music: " + x)
@eel.expose
def stop_music():
print("Music Stopped")
mixer.music.stop()
@eel.expose
def pause_music():
global paused
paused = True
mixer.music.pause()
eel.start('main.html', size=(500, 500))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question