如何在 Skype 上打来电话时以编程方式暂停 spotify
Posted
技术标签:
【中文标题】如何在 Skype 上打来电话时以编程方式暂停 spotify【英文标题】:How to programatically pause spotify when a call comes in on skype 【发布时间】:2011-02-16 07:10:56 【问题描述】:Skype 有一个内置功能,当有来电时,iTunes 播放会自动暂停和恢复。如果 Spotify 有类似的功能,那就太好了。两者都提供了一个 python API,所以这似乎是一条显而易见的路线。
【问题讨论】:
【参考方案1】:我曾尝试在 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)
【讨论】:
以上是关于如何在 Skype 上打来电话时以编程方式暂停 spotify的主要内容,如果未能解决你的问题,请参考以下文章