0

im trying to build a program (using pysimplegui) which contains a few buttons (play, stop, pause, next, previous) as you can see. and when i press "next" its stopping for some time and then the same music continues (i dont press "previous" because i know that will cause problem 0 - 1 = -1). `

global n
n = 0
media_player = vlc.MediaPlayer() 
url = ['http://cast.radiogroup.com.ua:8000/avtoradio', 'http://listen.rpfm.ru:9000/premium128', 'http://cast.loungefm.com.ua/terrace128']
media_player.set_mrl(url[n])
if event == 'play':
  media_player.play()

if event == 'stop': 
  media_player.stop()
     
if event == 'pause':
  media_player.pause()

if event == 'next':
  global n
  n + 1
  media_player.set_mrl(url[n])
  media_player.play()
        
if event == 'previous':
  n - 1
  media_player.set_mrl(url[n])
  media_player.play()

`

  1. ive tried to google this problem
  2. i didnt find the documentation
  3. im trying to run it in a bit different way, using `
import vlc
playlist_url = ['http://cast.radiogroup.com.ua:8000/avtoradio', 'http://listen.rpfm.ru:9000/premium128', 'http://cast.loungefm.com.ua/terrace128']
n = int(input())
instance = vlc.Instance('--intf dummy')
player = instance.media_list_player_new() 
media = instance.media_list_new(playlist_url[n])
player.set_media_list(media)  
player.play()

` but it returns [0000027223bc32e0] filesystem stream error: cannot open file C:\Users\dadva\Desktop\Project\h (No such file or directory) [0000027223ba3220] main input error: Your input can't be opened [0000027223ba3220] main input error: VLC is unable to open the MRL 'file:///C:/Users/dadva/Desktop/Project/h'. Check the log for details.

1
  • In your first code: n - 1 and n + 1 don't do anything, the result of the calculation is immediately discarded. You probably want n = n - 1 and n = n + 1. So when you hit "next", it stops playing, re-queries the (same) URL, and plays again. This is probably the short delay you notice. Commented Nov 10, 2022 at 16:48

1 Answer 1

0

Demo Code

import vlc
import PySimpleGUI as sg

playlist_url = [
    'http://cast.radiogroup.com.ua:8000/avtoradio',
    'http://listen.rpfm.ru:9000/premium128',
    'http://cast.loungefm.com.ua/terrace128',
]
n, m = 0, len(playlist_url)

player = vlc.MediaPlayer()
player.set_mrl(playlist_url[n])
player.play()

layout = [[sg.Button('PREV'), sg.Button('NEXT')]]
window = sg.Window('VLC Player', layout)

while True:

    event, values = window.read()

    if event == sg.WIN_CLOSED:
        break
    elif event in ('PREV', 'NEXT'):
        n = (n+1) % m if event == 'NEXT' else (n-1) % m
        player.set_mrl(playlist_url[n])
        player.play()

player.stop()
window.close()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.