gpt4 book ai didi

python - 如何在 Skype 上有来电时以编程方式暂停 Spotify

转载 作者:太空狗 更新时间:2023-10-30 01:03:58 24 4
gpt4 key购买 nike

Skype 有一个内置功能,当有来电时,iTunes 播放会暂停并自动恢复。如果 Spotify 有类似的功能就好了。两者都提供了一个 python API,所以这似乎是一个明显的下降路径。

最佳答案

我试过用 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)

关于python - 如何在 Skype 上有来电时以编程方式暂停 Spotify,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2779578/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com