Advertisement
Guest User

Tuner Code

a guest
Feb 20th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. radiourl = [
  2. 'http://ice6.somafm.com/groovesalad-16-aac',
  3. 'http://ice2.somafm.com/dronezone-32-aac',
  4. 'http://ice2.somafm.com/indiepop-32-aac',
  5. 'http://ice2.somafm.com/spacestation-32-aac',
  6. 'http://ice2.somafm.com/secretagent-32-aac',
  7. 'http://ice2.somafm.com/lush-32-aac',
  8. 'http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk',
  9. ]
  10.  
  11. import pygame, sys
  12. from pygame.locals import *
  13. import math
  14. import vlc
  15. import time
  16. import random
  17. import pyautogui
  18.  
  19. pyautogui.PAUSE = 1
  20. pyautogui.FAILSAFE = True
  21.  
  22. size = pyautogui.size()
  23.  
  24. xdim = size[0]
  25. ydim = size[1]
  26.  
  27. locations = []
  28.  
  29. WHITE=(255,255,255)
  30. BLUE=(0,0,255)
  31. threshold = 200
  32.  
  33. #define VLC instance
  34. instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
  35. #Define VLC player
  36. player=instance.media_player_new()
  37. #Define VLC media
  38.  
  39. players = []
  40. for x in radiourl:
  41. players.append(instance.media_player_new())
  42.  
  43. # set states for each url
  44. global play
  45. play = []
  46. for x in radiourl:
  47. play.append(0)
  48. print(play)
  49.  
  50. def checkProximity():
  51. global play
  52. #mouse coordinates
  53. ms = pygame.mouse.get_pos()
  54. index = 0
  55. for x in locations:
  56. c = math.sqrt((x[0]-ms[0])*(x[0]-ms[0]) + (x[1]-ms[1])*(x[1]-ms[1]))
  57. if c <= threshold:
  58. p = c/threshold*100
  59. p = int(100-p)
  60. players[index].audio_set_volume(p)
  61. if play[index] == 0:
  62. print("playing" + str(index))
  63. play[index]=1
  64. print(radiourl[index])
  65. media=instance.media_new(radiourl[index])
  66. #Set player media
  67. players[index].set_media(media)
  68. #Play the media
  69. players[index].play()
  70. else:
  71. play[index]=0
  72. players[index].stop()
  73. index = index+1
  74.  
  75. def main():
  76. pygame.init()
  77.  
  78. DISPLAY=pygame.display.set_mode((xdim,ydim),0,32)
  79. DISPLAY.fill(WHITE)
  80.  
  81. #pygame.mouse.set_visible(False)
  82.  
  83. for x in radiourl:
  84. rndCor = (random.uniform(threshold/2, xdim), random.uniform(threshold/2, ydim))
  85. locations.append(rndCor)
  86. pygame.draw.circle(DISPLAY, BLUE, (int(rndCor[0]), int(rndCor[1])), threshold)
  87.  
  88. print(locations)
  89.  
  90. while True:
  91. for event in pygame.event.get():
  92. if event.type==QUIT:
  93. pygame.quit()
  94. sys.exit()
  95. pygame.display.update()
  96. ms = pygame.mouse.get_pos()
  97. rel = pygame.mouse.get_rel()
  98. print(str(rel))
  99. if ms[0] < 2:
  100. print("less")
  101. pyautogui.moveTo([xdim,ms[1]])
  102. if ms[0] > xdim-2:
  103. pyautogui.moveTo([3, ms[1]])
  104. if ms[1] < 2:
  105. pyautogui.moveTo([ydim, ms[0]])
  106. if ms[1] > ydim-2:
  107. pyautogui.moveTo([3, ms[0]])
  108. checkProximity()
  109. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement