Saturday, December 26, 2020

ADDING MUSIC IN PYTHON

    ADDING MUSIC IN A PYTHON      PROGRAMME

  

Hey there, I'm gonna show how to add music in python programming.



As you can see we'll use a new function mixer.music( )  in order to import music in python programme.

Make sure you have installed pygame from the Windows Command Prompt.

Here's the source code


from pygame import mixer 


mixer.init() 


mixer.music.load("song.mp3"

mixer.music.set_volume(0.7


mixer.music.play() 


while True
    
    print("Press 'p' to pause, 'r' to resume"
    print("Press 'e' to exit the program"
    query = input(" "
    
    if query == 'p'

         
        mixer.music.pause()  
    elif query == 'r'

    
        mixer.music.unpause() 
    elif query == 'e'

        
        mixer.music.stop() 
        break


               Watch the video to see the output of the programme.





THANKS FOR VISITING





No comments:

Post a Comment