如何在Skype上发出呼叫时以编程方式暂停spotify

时间:2010-05-06 08:26:09

标签: python skype spotify

Skype具有内置功能,可以暂停iTunes播放并在呼叫进入时自动恢复。对于Spotify来说,有类似的东西会很不错。两者都提供了一个python API,所以这似乎是明显的下降路径。

1 个答案:

答案 0 :(得分:6)

我已经在python中做了这个。它作为守护进程在后台运行,在呼叫到来时暂停/恢复spotify。它使用Skype和Linux的Python库。 Spotify的:

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)