

def on_start(channel, event):
    'Callback for StasisStart events.\n\n    On new channels, answer, play demo-congrats, and register a DTMF listener.\n\n    :param channel: Channel DTMF was received from.\n    :param event: Event.\n    '
    channel.answer()
    playback = channel.play(media='sound:demo-congrats')

    def on_dtmf(channel, event):
        'Callback for DTMF events.\n\n        DTMF events control the playback operation.\n\n        :param channel: Channel DTMF was received on.\n        :param event: Event.\n        '
        digit = event['digit']
        if (digit == '5'):
            playback.control(operation='pause')
        elif (digit == '8'):
            playback.control(operation='unpause')
        elif (digit == '4'):
            playback.control(operation='reverse')
        elif (digit == '6'):
            playback.control(operation='forward')
        elif (digit == '2'):
            playback.control(operation='restart')
        elif (digit == '#'):
            playback.stop()
            channel.continueInDialplan()
        else:
            ((print >> sys.stderr), ('Unknown DTMF %s' % digit))
    channel.on_event('ChannelDtmfReceived', on_dtmf)

dataset/ETHPy150Open asterisk/ari-py/examples/playback_example.py on_start/original