Python - Pygame script will run in shell but not from script [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
This python script is part of a project but that doesn't have relevance. The script is attempting to use the pygame mixer module to load a wav file and play it; this works fine if I input the same code line-by-line in shell but not if I put it into a script and attempt to run it.
from pygame import mixer
mixer.init()
mixer.music.load('sound.wav')
mixer.music.play()
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
python
closed as off-topic by Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov Oct 14 '17 at 3:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov
add a comment |Â
up vote
1
down vote
favorite
This python script is part of a project but that doesn't have relevance. The script is attempting to use the pygame mixer module to load a wav file and play it; this works fine if I input the same code line-by-line in shell but not if I put it into a script and attempt to run it.
from pygame import mixer
mixer.init()
mixer.music.load('sound.wav')
mixer.music.play()
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
python
closed as off-topic by Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov Oct 14 '17 at 3:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov
Not working how?
â thrig
Oct 13 '17 at 20:56
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
This python script is part of a project but that doesn't have relevance. The script is attempting to use the pygame mixer module to load a wav file and play it; this works fine if I input the same code line-by-line in shell but not if I put it into a script and attempt to run it.
from pygame import mixer
mixer.init()
mixer.music.load('sound.wav')
mixer.music.play()
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
python
This python script is part of a project but that doesn't have relevance. The script is attempting to use the pygame mixer module to load a wav file and play it; this works fine if I input the same code line-by-line in shell but not if I put it into a script and attempt to run it.
from pygame import mixer
mixer.init()
mixer.music.load('sound.wav')
mixer.music.play()
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
python
edited Oct 13 '17 at 20:59
asked Oct 13 '17 at 20:41
Josh Stafford
163
163
closed as off-topic by Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov Oct 14 '17 at 3:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov
closed as off-topic by Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov Oct 14 '17 at 3:26
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." â Michael Homer, GAD3R, Stephen Rauch, Jeff Schaller, Romeo Ninov
Not working how?
â thrig
Oct 13 '17 at 20:56
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58
add a comment |Â
Not working how?
â thrig
Oct 13 '17 at 20:56
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58
Not working how?
â thrig
Oct 13 '17 at 20:56
Not working how?
â thrig
Oct 13 '17 at 20:56
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.
add a comment |Â
up vote
1
down vote
It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.
It turns out the script was ending before the audio file had time to play so adding a sleep(length of audio clip) to the end of the file gave the script time to play the clip.
edited Oct 13 '17 at 21:15
answered Oct 13 '17 at 21:08
Josh Stafford
163
163
add a comment |Â
add a comment |Â
Not working how?
â thrig
Oct 13 '17 at 20:56
If I run the script line-by-line in shell, the sound plays through the speakers fine but if I put it into a script and do 'python3 playSound.py' then the audio file does not play.
â Josh Stafford
Oct 13 '17 at 20:57
@JoshStafford please edit your question to provide additional information - comments can get lost.
â guntbert
Oct 13 '17 at 20:58