如何在Skype来电时程序性地暂停Spotify
Skype有一个内置功能,当有电话打进来时,它会自动暂停和恢复iTunes的播放。如果Spotify也能有类似的功能就好了。两者都提供了Python的接口,所以用这个方法来实现看起来是个不错的选择。
1 个回答
6
我尝试用Python来实现这个功能。它在后台运行,像个守护进程一样,当有电话打进来时,会暂停或恢复Spotify的播放。这个程序使用了Skype和Spotify的Python库:
http://code.google.com/p/pytify/
https://developer.skype.com/wiki/Skype4Py
import Skype4Py
import time
from pytify import Spotify
# Create Skype object
skype = Skype4Py.Skype()
skype.Attach()
# Create Spotify object
spotify = Spotify()
spotifyPlaying = spotify.isPlaying()
# Create handler for when Skype call status changes
def on_call_status(call, status):
if status == Skype4Py.clsInProgress:
# Save current spotify state
global spotifyPlaying
spotifyPlaying = spotify.isPlaying()
if spotify.isPlaying():
print "Call started, pausing spotify"
# Call started, pause Spotify
spotify.stop()
elif status == Skype4Py.clsFinished:
# Call finished, resume Spotify if it was playing
if spotifyPlaying and not spotify.isPlaying():
print "Call finished, resuming spotify"
spotify.playpause()
skype.OnCallStatus = on_call_status
while True:
time.sleep(10)