0

I'm writing a player program in python.

The effect I want to achieve is to get a signal after playing a song and then go to the next song.

some code:

def end_call_back(event):
    print('call:', 'a song finished')


if "__main__" == __name__:
    app = App()
    app.player.play('sample1.mp4')
    app.player.add_callback(vlc.EventType.MediaPlayerStopped, end_call_back)

    **# Here , I want to received a signal to play the next song.**

    app.mainloop()

now, I can get the sentence in the console,“a song finished”

What should I do next in the main process to get a signal to play the next song?

Youyou Hua
  • 49
  • 5
  • Wouldn't it be the same thing you did to play the first song? I would think if you mean for it to keep playing, I would add it to your `end_call_back` delegate code. – Ben Y Jul 13 '21 at 18:15
  • @BenY, I tried. Simply adding a sentence `app.player.play('next-song.mp4')` in `end_call_back` delegate code. But it doesn't work. – Youyou Hua Jul 13 '21 at 18:22
  • 1
    I don't know what framework you are using, as you did not add the tag, so I am unable to provide any way to inject actions into the main loop. – Ben Y Jul 13 '21 at 18:34
  • @BenY Python-3.7, python-vlc, tkinter. If you can give some advice, thank you in advance. – Youyou Hua Jul 13 '21 at 18:39
  • If `app` is an instance of custom class inherited from `Tk()`, then try calling `app.after(10, app.player.play, "sample2.mp4")` inside `end_call_back()`. – acw1668 Jul 14 '21 at 02:59

0 Answers0