MyreMylar / pygame_gui_examples

Some examples of how to use pygame_gui
141 stars 43 forks source link

Issue with another python package, like vlc. #12

Closed catafest closed 2 years ago

catafest commented 2 years ago

I want to use it with vlc python package. Can this done? Can you provide one example? Waht are the limitations of the pygame_gui with another python package? Thank you. This is the default source code for vlc:

# importing vlc module
import vlc
import time

# creating vlc media player object
media_player = vlc.MediaPlayer("1.mp4")

# start playing video
media_player.play()

# wait so the video can be played for 5 seconds
# irrespective for length of video
time.sleep(5)
MyreMylar commented 2 years ago

Hello,

Since it looks like you are interested in playing video I'm going to point you to a recently created test project I created using pyvidplayer with a pygame_gui window. You can find pyvidplayer here and the test video I used here.

Code is here:

import pygame
from pyvidplayer import Video

from pygame_gui.ui_manager import UIManager
from pygame_gui.elements.ui_window import UIWindow
from pygame_gui.elements.ui_image import UIImage

class VideoWindow(UIWindow):
    def __init__(self, position, ui_manager, video_path, video_title):
        super().__init__(pygame.Rect(position, (800, 600)), ui_manager,
                         window_display_title=video_title,
                         object_id='#video_window')

        video_surface_size = self.get_container().get_size()
        self.video_surface_element = UIImage(pygame.Rect((0, 0), video_surface_size),
                                             pygame.Surface(video_surface_size).convert(),
                                             manager=ui_manager,
                                             container=self,
                                             parent_element=self)

        self.video = Video(video_path)
        self.video.set_size(video_surface_size)

        self.is_active = False

    def update(self, time_delta):
        super().update(time_delta)

        self.video.draw(self.video_surface_element.image, (0, 0), force_draw=False)

    def kill(self):
        super().kill()
        self.video.close()

class WindowedVideoApp:
    def __init__(self):
        pygame.init()

        self.root_window_surface = pygame.display.set_mode((1280, 720))
        self.background_surface = pygame.Surface((1280, 720)).convert()
        self.background_surface.fill(pygame.Color('#505050'))
        self.ui_manager = UIManager((1280, 720))
        self.clock = pygame.time.Clock()
        self.is_running = True

        self.video_window = VideoWindow((25, 25), self.ui_manager,
                                        video_path="data/BigBuckBunny.mp4",
                                        video_title='BigBuckBunny.mp4')

    def run(self):
        while self.is_running:
            time_delta = self.clock.tick(60)/1000.0

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.video_window.kill()
                    self.is_running = False

                self.ui_manager.process_events(event)

            self.ui_manager.update(time_delta)

            self.root_window_surface.blit(self.background_surface, (0, 0))
            self.ui_manager.draw_ui(self.root_window_surface)

            pygame.display.update()

if __name__ == '__main__':
    app = WindowedVideoApp()
    app.run()

And it looks like this when running:

image

Plays absolutely fine on my Windows PC.

Hope that helps!

catafest commented 2 years ago

I cannot install it, I try with : and I don't find build on http://ffmpeg.zeranoe.com/builds/ ...

C:\Python310>python.exe -m pip install https://github.com/matham/ffpyplayer/archive/master.zip
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> ffpyplayer

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
MyreMylar commented 2 years ago

I would report that issue to ffpyplayer, not to me.

I know it is possible to install ffpyplayer on python 3.9 and with a slightly behind the bleeding edge version of pip, though I was using the pycharm GUI to install rather than any specific command line. No doubt pip is trying to change how package installing works for some reason.

Good luck.

On Tue, 1 Feb 2022, 20:24 Cătălin George Feștilă, @.***> wrote:

I cannot install it, I try with :

C:\Python310>python.exe -m pip install https://github.com/matham/ffpyplayer/archive/master.zip

...

note: This error originates from a subprocess, and is likely not a problem with pip.

error: legacy-install-failure

× Encountered error while trying to install package.

╰─> ffpyplayer

note: This is an issue with the package mentioned above, not pip.

hint: See above for output from the failure.

— Reply to this email directly, view it on GitHub https://github.com/MyreMylar/pygame_gui_examples/issues/12#issuecomment-1027254582, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDGGQVZZXCXTTHKJKW6KLUZA6RTANCNFSM5NEUIASQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

catafest commented 2 years ago

install on windows os need to use SDL ... https://matham.github.io/ffpyplayer/installation.html#windows this issue is closed

MyreMylar commented 2 years ago

There are binary wheels for ffpyplayer for windows so it should install fine from pip. pygame also uses SDL.