示例#1
0
AVAudioSession = ObjCClass('AVAudioSession')
AVPlayer = ObjCClass('AVPlayer')
AVPlayerItem = ObjCClass('AVPlayerItem')
NSURL = ObjCClass('NSURL')

# Set Pythonista app to play non-blocking, 'mixed with others' sounds
audio_session = AVAudioSession.sharedInstance()
audio_session.setCategory_withOptions_error_('AVAudioSessionCategoryPlayback', 1, None)

# Create the item to play
sound = NSURL.fileURLWithPath_('silence.mp3')
item = AVPlayerItem.playerItemWithURL_(sound)

# Play the sound (only once)
player = AVPlayer.alloc().initWithPlayerItem_(item)
player.setActionAtItemEnd_(2)
player.play()

while True:
    print 'Still running', datetime.now()
    sleep(1)

# --------------------

time.sleep(1)

# --------------------

# coding: utf-8

import sound