Как программно приостановить спойт при входящем звонке по скайпу - PullRequest
5 голосов
/ 06 мая 2010

Skype имеет встроенную функцию, при которой воспроизведение iTunes автоматически приостанавливается и возобновляется при поступлении вызова. Было бы неплохо иметь что-то подобное для Spotify. Оба предоставляют Python API, поэтому это может показаться очевидным путем.

1 Ответ

6 голосов
/ 06 мая 2010

Я попробовал это сделать на python. Он работает в фоновом режиме как демон, приостанавливая / возобновляя spotify при поступлении вызова. Он использует библиотеки Python для Skype & 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)
...