Wednesday, August 17, 2016

Minim 11. pause

This sketch demonstrates the pause() method of AudioPlayer.


By pressing any key, so keyPressed() is called, we can pause() or loop().


# Ex11.pyde
# Based on Java File in Examples: pause.pde

'''
This sketch demonstrates how to use the pause method of a
Playable class. The class used here is AudioPlayer, but
you can also pause an AudioSnippet. Pausing a Playable
causes it to cease playback but not change position, so
that when you resume playback it will start from where
you last paused it. Press 'p' to pause the player.
'''

add_library('minim')

groove = None

def setup():
    size(512, 200)
    global groove
    minim = Minim(this)
    groove = minim.loadFile("groove.mp3", 2048)
    groove.loop()
    
def draw():
    background(0)
    stroke(255)
    for i in range(groove.bufferSize()-1):
        line(i, 50 + groove.left.get(i)*50, 
             i+1, 50 + groove.left.get(i+1)*50 )
        line(i, 150 + groove.right.get(i)*50,
             i+1, 150 + groove.right.get(i+1)*50)
        
def keyPressed():
    if groove.isPlaying():
        groove.pause()
    else:
        groove.loop()

This is the output:


No comments:

Post a Comment