Python - Pygame script will run in shell but not from script [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash 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.







share|improve this question














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
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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














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.







share|improve this question














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
If this question can be reworded to fit the rules in the help center, please edit the question.












  • 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












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.







share|improve this question














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.









share|improve this question













share|improve this question




share|improve this question








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
If this question can be reworded to fit the rules in the help center, please edit the question.




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
If this question can be reworded to fit the rules in the help center, please edit the question.











  • 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










  • 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










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.






share|improve this answer





























    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.






    share|improve this answer


























      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.






      share|improve this answer
























        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.






        share|improve this answer














        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.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 13 '17 at 21:15

























        answered Oct 13 '17 at 21:08









        Josh Stafford

        163




        163












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay