Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. import vlc
  2. import time
  3.  
  4. url="http://tvradio.ert.gr/radio/liveradio/asx/net.asx"
  5. global flag
  6. global m
  7. global i
  8. global p
  9. flag = 0
  10.  
  11. def end_reached(self):
  12.     global flag
  13.     flag = 1
  14.     print("End reached!")
  15.  
  16. def VLC_play(file):
  17.     global m
  18.     global p
  19.     global i
  20.     global flag
  21.     m=i.media_new(file) # Create new media
  22.     p.set_media(m) # Set URL as the player's media
  23.     m.release()
  24.     p.play() # play it
  25.  
  26.     while flag == 0: # Wait until the end of the first media has been reached...
  27.         time.sleep(0.5)
  28.         print('Loading playlist...')
  29.     flag = 0
  30.     sub_list = m.subitems() # .. and get the sub itmes in the playlist
  31.     sub_list.lock()
  32.     sub = sub_list.item_at_index(0) # Get the first sub item
  33.     sub_list.unlock()
  34.     sub_list.release()
  35.     p.set_media(sub) # Set it as the new media in the player
  36.     p.play() # and play it
  37.     sub.release()
  38.     a = 0
  39.     while p.is_playing()==0: # This is just a counter that runs until the stream is actually being played
  40.         time.sleep(0.5)
  41.         a += 1
  42.         print(a)
  43.  
  44. i=vlc.Instance() #Create VLC instance
  45. p=i.media_player_new() # Create new media player
  46. event_manager = p.event_manager() # Attach event to player (next 3 lines)
  47. event=vlc.EventType()
  48. event_manager.event_attach(event.MediaPlayerEndReached, end_reached)
  49. VLC_play(url)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement