编程语言
首页 > 编程语言> > python – 如何在Skype上调用时以编程方式暂停spotify

python – 如何在Skype上调用时以编程方式暂停spotify

作者:互联网

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

解决方法:

我已经在python中做了这个.它作为守护进程在后台运行,在呼叫到来时暂停/恢复spotify.它使用Skype和LinuxPython库. 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)

标签:python,skype,spotify
来源: https://codeday.me/bug/20190518/1130233.html