Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5054

Python • Re: KeyboardInterrupt in While True statement

$
0
0
Sorry I didnt post all of my code. I should have thought that it might be other parts contributing as well. See below.

You might see other attempts to stop this program, like an additional button that would also trigger quitting, but that didnt work either.

Code:

from gpiozero import LED, Buttonfrom time import sleepfrom signal import pauseimport time, vlcimport sysled = LED(17)button = Button(2)stopper = Button(4)def image(source):        # creating a vlc instance        vlc_instance = vlc.Instance()        # creating a media player        player = vlc_instance.media_player_new()        #full screen        player.toggle_fullscreen()        #creating a media        media = vlc_instance.media_new(source)        # setting media to the player        player.set_media(media)        # play the video        player.play()        if stopper.is_pressed:                quit()def video(source):        # creating a vlc instance        vlc_instance = vlc.Instance()        # creating a media player        player = vlc_instance.media_player_new()        #full screen        player.toggle_fullscreen()        #creating a media        media = vlc_instance.media_new(source)        # setting media to the player        player.set_media(media)        # play the video        player.play()        # wait time        time.sleep(5)        # getting the duration of the video        duration = player.get_length()        # printing the duration of the video        print("Duration : " + str(duration))print("Press the button to start the program!")button.wait_for_press()try:        while True:                        led.off()                        # call the image method                        image("elevator.jpg")                        while(button.is_pressed == False):                                pass                        led.on()                        time.sleep(2)                        # call the video method                        video("handshake1080.mp4")                        led.off()except KeyboardInterrupt:        quit()

Statistics: Posted by alfordtp — Mon Jan 20, 2025 2:24 am



Viewing all articles
Browse latest Browse all 5054

Trending Articles