2

So I'm trying to implement some videos onto an already existing pygame program that uses the pygame_functions (see https://github.com/StevePaget/Pygame_Functions/blob/master/pygame_functions.py). I found a pyvidplayer that seems to allow videos on python with very simple code (https://github.com/ree1261/pyvidplayer/blob/main/pyvidplayer.py). I've tried implementing a video to a step of the task, but when I run this code, the program gets stuck. After getting the participant's name the task usually follows with the instructions page, but in my case (after adding the video) it freezes.

Ideally I would like the program to continue once the video is finished as it did before.

The programs main.py starts off like this

pygame.init()
pygame.font.init()
screenSize = (1200, 800)  
size = (6, 6)  # can be changed to any n x m grid

# add participant information
part = Start(screenSize, overall_score)
participant = part.add_participant()

# display consent
start = Start(screenSize, overall_score)
cons = start.add_consent()

# start the game and get username
start = Start(screenSize, overall_score)
username = start.add_name()

# display instruction
start = Start(screenSize, overall_score)
instr = start.add_instruction()

Here is the start Class and the definition I added the video to:

class Start:
    def __init__(self, screenSize, overall_score):
        self.screenSize = screenSize
        self.overall_score = overall_score
        self.username = None
        self.participant = None
        self.instruction = None
        self.robot = None
        self.consent = None

    def add_name(self):

        screen = screenSize(self.screenSize[0], self.screenSize[1])
        screen
        setBackgroundColour("white")
        videoSurface = pygame.Surface((800,800))

        instruction = makeLabel("Please enter a nickname: ", 30, 240, 30, "black", "Arial", "white")
        showLabel(instruction)

        wordBox = makeTextBox(240, 110, 300, 0, "Enter Text here", 0, 24)
        showTextBox(wordBox)
        
        vid = Video(r"Clips/Edited_welcome_name.mp4")
        vid.set_size((800,800))

        while True:
            
            vid.draw(videoSurface, (0, 0))
            screen.blit(videoSurface, (600,0))
            pygame.display.update()
            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    vid.close()
                    videoSurface.fill((255,255,255))
                    screen.blit(videoSurface, (600,0))
                    

        self.username = textBoxInput(wordBox)
        return self.username

Any help would be greatly appreciated. Please bare in mind I'm very new to pygame and don't really know what I'm doing.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
Ukiyo-e
  • 31
  • 3
  • 1
    Welcome back to Stack Overflow. Please read [ask] and try to focus the code and the question on a specific problem, and *explicitly ask* about that problem - we cannot just give you ["any help"](https://meta.stackoverflow.com/questions/284236). Try to figure out what parts of the code are relevant to causing (and showing) the problem, and create a [mre]. – Karl Knechtel May 28 '22 at 15:42
  • 3
    To be clear: the intent is that creating a `Start` instance and calling `add_name` will run the main loop of the program? Try to think about the logic here. If there is a `while True:` loop, then how is the method supposed to complete? What is the purpose of `self.username = textBoxInput(wordBox)`? Should it happen before or after (or perhaps during?) the main loop of the program? Why? Actually, where does `textBoxInput` come from? It doesn't appear to be built in to Pygame. Did you try reading documentation for that, or looking for a tutorial? – Karl Knechtel May 28 '22 at 15:45
  • 1
    [How to load and play a video in pygame](https://stackoverflow.com/questions/21356439/how-to-load-and-play-a-video-in-pygame/69054207#69054207) – Rabbid76 May 28 '22 at 17:19

0 Answers0