Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- radiourl = [
- 'http://ice6.somafm.com/groovesalad-16-aac',
- 'http://ice2.somafm.com/dronezone-32-aac',
- 'http://ice2.somafm.com/indiepop-32-aac',
- 'http://ice2.somafm.com/spacestation-32-aac',
- 'http://ice2.somafm.com/secretagent-32-aac',
- 'http://ice2.somafm.com/lush-32-aac',
- 'http://bbcwssc.ic.llnwd.net/stream/bbcwssc_mp1_ws-eieuk',
- ]
- import pygame, sys
- from pygame.locals import *
- import math
- import vlc
- import time
- import random
- import pyautogui
- pyautogui.PAUSE = 1
- pyautogui.FAILSAFE = True
- size = pyautogui.size()
- xdim = size[0]
- ydim = size[1]
- locations = []
- WHITE=(255,255,255)
- BLUE=(0,0,255)
- threshold = 200
- #define VLC instance
- instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
- #Define VLC player
- player=instance.media_player_new()
- #Define VLC media
- players = []
- for x in radiourl:
- players.append(instance.media_player_new())
- # set states for each url
- global play
- play = []
- for x in radiourl:
- play.append(0)
- print(play)
- def checkProximity():
- global play
- #mouse coordinates
- ms = pygame.mouse.get_pos()
- index = 0
- for x in locations:
- c = math.sqrt((x[0]-ms[0])*(x[0]-ms[0]) + (x[1]-ms[1])*(x[1]-ms[1]))
- if c <= threshold:
- p = c/threshold*100
- p = int(100-p)
- players[index].audio_set_volume(p)
- if play[index] == 0:
- print("playing" + str(index))
- play[index]=1
- print(radiourl[index])
- media=instance.media_new(radiourl[index])
- #Set player media
- players[index].set_media(media)
- #Play the media
- players[index].play()
- else:
- play[index]=0
- players[index].stop()
- index = index+1
- def main():
- pygame.init()
- DISPLAY=pygame.display.set_mode((xdim,ydim),0,32)
- DISPLAY.fill(WHITE)
- #pygame.mouse.set_visible(False)
- for x in radiourl:
- rndCor = (random.uniform(threshold/2, xdim), random.uniform(threshold/2, ydim))
- locations.append(rndCor)
- pygame.draw.circle(DISPLAY, BLUE, (int(rndCor[0]), int(rndCor[1])), threshold)
- print(locations)
- while True:
- for event in pygame.event.get():
- if event.type==QUIT:
- pygame.quit()
- sys.exit()
- pygame.display.update()
- ms = pygame.mouse.get_pos()
- rel = pygame.mouse.get_rel()
- print(str(rel))
- if ms[0] < 2:
- print("less")
- pyautogui.moveTo([xdim,ms[1]])
- if ms[0] > xdim-2:
- pyautogui.moveTo([3, ms[1]])
- if ms[1] < 2:
- pyautogui.moveTo([ydim, ms[0]])
- if ms[1] > ydim-2:
- pyautogui.moveTo([3, ms[0]])
- checkProximity()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement