如何在skyp上接到呼叫时以编程方式暂停spotify

2024-05-18 20:53:59 发布

您现在位置:Python中文网/ 问答频道 /正文

Skype有一个内置的功能,当有电话进来时,iTunes播放会暂停并自动恢复。如果Spotify也有类似的功能,那就太好了。两者都提供了一个pythonapi,因此这似乎是一个很明显的解决方法。在


Tags: 方法功能pythonapiitunes内置spotify电话skype
1条回答
网友
1楼 · 发布于 2024-05-18 20:53:59

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

相关问题 更多 >

    热门问题