Python Forum
[Kivy] video plays in the background only
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] video plays in the background only
#1
I am trying to play video, the video is playing on the background only and no window is shown. this the function that plays the video in a class.
class Firstwindow(Screen):
    def on_pre_enter(self,*args):
        video= VideoPlayer(source ='react.mp4')
        video.state ='play'
        video.allow_fullscreen=True
        return video
kv file
    <Firstwindow>:
     canvas:
          Rectangle:
               source:"down.jpg"
               size: self.size
     name: "home_screen"
     id: home_screen
     Button:
          id: b1
          text: 'Beginner'
          color:"purple"
          pos:130,300
          size_hint:(0.5,0.1)
          on_release:
               app.root.current="w_screen"
               root.manager.transition.direction= "right"
          
     Button:
          id: b2
          text:" Inermediate"
          color:"purple"
          pos:130,230
          size_hint:(0.5,0.1)
          on_release:
               app.root.current="menu_screen"
               root.manager.transition.direction= "right"
     Button:
          id: b3
          text:"Advanced"
          color:"purple"
          pos:130,160
          size_hint:(0.5,0.1)
          on_release:
               app.root.current="ww"
               root.manager.transition.direction= "right"
deanhystad write Jun-17-2024, 07:00 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
this the entire code
main.py

import kivy


from kivy.config import Config
Config.set('graphics', 'width', '400')
Config.set('graphics', 'height', '500')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.label import Label
from kivy.uix.image import Image
import sqlite3
from kivy.uix.screenmanager import ScreenManager,Screen
import random
from kivy.core.audio import SoundLoader
from kivy.properties import ObjectProperty
from kivy.uix.videoplayer import VideoPlayer
from kivy.uix.widget import Widget



class Playvideo(Screen):
    def on_pre_enter(self,*args):
        video= VideoPlayer(source ='react.mp4')
        video.state ='play'
        video.allow_fullscreen=True
        
        return video
    
    
    
    

class mywidget(Screen):
   def pressed(self):
    self.ids.l1.text="text"

        
            
        
    
        
    
        


class Firstwindow(Screen):
    pass
    
        
            
            
    
    
    
            
            
class Secondwindow(Screen):
    global x1
    global re,re1,re2,re3,re4
    
            
    db = sqlite3.connect('book.db')
    cu = db.cursor()
    cu1= db.cursor()
    cu2 = db.cursor()
    cu3 = db.cursor()
    cu4= db.cursor()
    choseOption =db.cursor()
    cu1.execute("select wronganswer1 from intermediate")
    cu.execute("select questions from intermediate")
    cu2.execute("select wronganswer2 from intermediate")
    cu3.execute("select rightanswer from intermediate")
    cu4.execute("select option from intermediate")
    re1= cu1.fetchall()
    re2= cu2.fetchall()
    re= cu.fetchall()
    re3 = cu3.fetchall()
    re4 = cu4.fetchall()

    
    def on_pre_enter(self,*args):
        global theoption
        x1 = random.randint(1,331)
        self.ids.record1.text= str (re[x1])
        self.ids.ll1.text = str (re1[x1])
        self.ids.ll2.text = str (re2[x1])
        self.ids.ll3.text = str (re3[x1])
        theoption = str(re4[x1])
        
        
    def build(self):
        video= VideoPlayer(source ='react.mp4')
        video.state ='play'
        video.allow_fullscreen=True
        return video
       
           
           
       
       
       
       
       
       
class Thirdwindow(Screen):

      
    global x 
    global results,result1,result2,result3
    
            
    db = sqlite3.connect('book.db')
    cur = db.cursor()
    cur1= db.cursor()
    cur2 = db.cursor()
    cur3 = db.cursor()
    cur1.execute("select wronganswer1 from advanced")
    cur.execute("select questions from advanced")
    cur2.execute("select wronganswer2 from advanced")
    cur3.execute("select rightanswer from advanced")
    result1= cur1.fetchall()
    result2= cur2.fetchall()
    results= cur.fetchall()
    result3 = cur3.fetchall()
    
    
    
    
    
     
    
    def on_pre_enter(self,*args):
        x = random.randint(1,244)
        self.ids.record.text = str (results[x])
        self.ids.l1.text = str (result1[x])
        self.ids.l2.text = str (result2[x])
        self.ids.l3.text = str (result3[x])
    
    
           
           
           
           
           
           





class Windowfirst(Screen):

      
    global r
    global s,s1,s2,s3
    
            
    db = sqlite3.connect('book.db')
    b = db.cursor()
    b1= db.cursor()
    b2 = db.cursor()
    b3 = db.cursor()
    b1.execute("select wronganswer1 from beginner")
    b.execute("select questions from beginner")
    b2.execute("select wronganswer2 from beginner")
    b3.execute("select rightanswer from beginner")
    s1= b1.fetchall()
    s2= b2.fetchall()
    s= b.fetchall()
    s3 = b3.fetchall()
    
    
    
    
    
     
    
    def on_pre_enter(self,*args):
        r = random.randint(1,253)
        self.ids.record3.text = str (s[r])
        self.ids.lll1.text = str (s1[r])
        self.ids.lll2.text = str (s2[r])
        self.ids.lll3.text = str (s3[r])






               

    


class WindowManager(ScreenManager):
    global theoption
    def screen_manager_method(self):
        pass
class CrashCourse(App):
    def build(self):
        Builder.load_file("crashcourse.kv")
        return WindowManager()
    
    
if __name__ == '__main__':
    CrashCourse().run()
kv file



Output:
<WindowManager>: Firstwindow: Secondwindow: Thirdwindow: Windowfirst: mywidget: Playvideo: <Firstwindow>: canvas: Rectangle: source:"down.jpg" size: self.size name: "home_screen" id: home_screen Button: id: b1 text: 'Beginner' color:"purple" pos:130,300 size_hint:(0.5,0.1) on_release: app.root.current="w_screen" root.manager.transition.direction= "right" Button: id: b2 text:" Inermediate" color:"purple" pos:130,230 size_hint:(0.5,0.1) on_release: app.root.current="menu_screen" root.manager.transition.direction= "right" Button: id: b3 text:"Advanced" color:"purple" pos:130,160 size_hint:(0.5,0.1) on_release: app.root.current="game_screen" root.manager.transition.direction= "right" <Secondwindow>: name: "menu_screen" id: menu_screen Label: id:record1 text:"" text_size:self.width, None pos_hint:{'x':0,'top':1.45} GridLayout padding:1 cols:2 Label: id:ll1 text:"" CheckBox: id:ch1 group:"mygroup" Label: text:"" id:ll2 CheckBox: group:"mygroup" Label: text:"" id:ll3 CheckBox: group:"mygroup" Button: text:"Move Next" on_press: root.on_pre_enter() size_hint:(0.4,0.4) Button: size_hint:(0.4,0.4) pos_hint:{'x':10} text:"Explain" on_press:root.build() <Thirdwindow>: name: "game_screen" id: game_screen Label: id:record text:"" text_size:self.width, None pos_hint:{'x':0,'top':1.45} GridLayout padding:50 spacing:50 cols:2 Label: id:l1 text:"" text_size:self.width, None CheckBox: id:ch1 group:"mygroup" Label: text:"" id:l2 text_size:self.width, None CheckBox: group:"mygroup" Label: text:"" id:l3 text_size:self.width, None CheckBox: group:"mygroup" Button: text:"Move Next" on_press: root.on_pre_enter() size_hint:(0.4,0.4) Button: size_hint:(0.4,0.4) pos_hint:{'x':10} text:"Explain" on_release: app.root.current="video" <Windowfirst>: name: "w_screen" id: w_screen Label: id:record3 text:"" text_size:self.width, None pos_hint:{'x':0,'top':1.45} GridLayout padding:1 cols:2 Label: id:lll1 text:"" CheckBox: id:ch1 group:"mygroup" Label: text:"" id:lll2 CheckBox: group:"mygroup" Label: text:"" id:lll3 CheckBox: group:"mygroup" Button: text:"Move Next" on_press: root.on_pre_enter() size_hint:(0.4,0.4) Button: size_hint:(0.4,0.4) pos_hint:{'x':10} text:"Explain" on_press:root.ch() <mywidget>: name:"ww" id:"ww" ActionBar: size:root.width, 50 pos_hint: {'top':1} background_color: .6, 4, .2, .6 ActionView: ActionPrevious: title: 'Action Bar' with_previous: False ActionGroup: text:"action" ActionButton: text:"verb to be" ActionButton: text:"present simple" <Playvideo>: name:"video" id:"video"


error message:

Error:
[ERROR ] [Image ] Error loading <react.mp4>
Larz60+ write Jun-17-2024, 09:14 PM:
Second request:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I have added tags for you this time. Please use BBCode tags on future posts.
Also, when posting errors, be sure to post entire unaltered error traceback, as it contains very useful debugging clues.
Reply
#3
PS G:\crash course> & C:/Users/gorashy/AppData/Local/Programs/Python/Python312/python.exe
"g:/crash course/main.py"
[INFO ] [Logger ] Record log in C:\Users\gorashy\.kivy\logs\kivy_24-06-17_15.txt
[INFO ] [deps ] Successfully imported "kivy_deps.gstreamer" 0.3.3
[INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.4.0
[INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.7.0
[INFO ] [Kivy ] v2.3.0
[INFO ] [Kivy ] Installed at "C:\Users\gorashy\AppData\Local\Programs\Python\Python312\Lib\site-packages\kivy\__init__.py"
[INFO ] [Python ] v3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
[INFO ] [Python ] Interpreter at "C:\Users\gorashy\AppData\Local\Programs\Python\Python312\python.exe"
[INFO ] [Logger ] Purge log fired. Processing...
[INFO ] [Logger ] Purge finished!
[INFO ] [Factory ] 195 symbols loaded
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [AudioGstplayer] Using Gstreamer 1.18.5.0
[INFO ] [Audio ] Providers: audio_gstplayer, audio_sdl2 (audio_ffpyplayer ignored)[INFO ] [VideoGstplayer] Using Gstreamer 1.18.5.0
[INFO ] [Video ] Provider: gstplayer
[INFO ] [Window ] Provider: sdl2
[INFO ] [Window ] Activate GLES2/ANGLE context
[INFO ] [GL ] Using the "OpenGL" graphics system
[INFO ] [GL ] Backend used <angle_sdl2>
[INFO ] [GL ] OpenGL version <b'OpenGL ES 2.0.0 (ANGLE 2.1.21998 git hash: 2eea91f8f0b2)'>
[INFO ] [GL ] OpenGL vendor <b'Google Inc. (Intel)'>
[INFO ] [GL ] OpenGL renderer <b'ANGLE (Intel, Intel® HD Graphics (0x00000046) Direct3D11 vs_4_0 ps_4_0, D3D11-8.15.10.2900)'>
[INFO ] [GL ] OpenGL parsed version: 2, 0
[INFO ] [GL ] Shading version <b'OpenGL ES GLSL ES 1.00 (ANGLE 2.1.21998 git hash: 2eea91f8f0b2)'>
[INFO ] [GL ] Texture max size <8192>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [Base ] Start application main loop
[INFO ] [GL ] NPOT texture support is available
[WARNING] [Multiple screens named "game_screen"] [<Screen name='game_screen'>, <Screen name='game_screen'>]
[WARNING] [Multiple screens named "video"] [<Screen name='video'>, <Screen name='video'>]
[ERROR ] [Image ] Error loading <react.mp4>

(python.exe:16228): GStreamer-WARNING **: 21:31:10.775: Failed to load plugin 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\gioopenssl.dll': 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\gioopenssl.dll': The specified module could not be found.

(python.exe:16228): GStreamer-WARNING **: 21:31:11.912: Failed to load plugin 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\gstrtmp.dll': 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\gstrtmp.dll': The specified module could not be found.

(python.exe:16228): GStreamer-WARNING **: 21:31:14.032: Failed to load plugin 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\librtmp-1.dll': 'C:\Users\gorashy\AppData\Local\Programs\Python\Python312\share\gstreamer\bin\librtmp-1.dll': The
specified module could not be found.
[INFO ] [Base ] Leaving application in progress...
PS G:\crash course>
Reply
#4
Are you trying to do something like this?



test.py
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.videoplayer import VideoPlayer


# define the Screens
class Window1(Screen):
    pass

class Window2(Screen):
    pass

class Window3(Screen):
    pass

class PlayVideo(Screen):
    pass

class MyWidget(Screen):
    pass


class WindowManager(ScreenManager):
    pass


kv = Builder.load_file('my.kv')

class MyApp(App):
    def build(self):
        return kv

MyApp().run()
my.kv
Output:
WindowManager: Window1: Window2: Window3: PlayVideo: MyWidget: <PlayVideo>: name: 'video_window' BoxLayout: orientation: 'vertical' spacing: 50 VideoPlayer: source: './videos/my.mp4' state: 'stop' size_hint_y: None height: root.height - 125 GridLayout: cols: 3 row_force_default: True row_default_height: 40 col_force_default: True col_default_width: 100 spacing: 10 padding: 10 Button: text: 'Goto 1' font_size: 20 on_release: app.root.current = 'window1' root.manager.transition.direction = 'up' Button: text: 'Goto 2' font_size: 20 on_release: app.root.current = 'window2' root.manager.transition.direction = 'up' Button: text: 'Goto 3' font_size: 20 on_release: app.root.current = 'window3' root.manager.transition.direction = 'up' <Window1>: name: 'window1' canvas.before: Color: rgba: (180/255, 50/255, 30/255, 1) Rectangle: pos: self.pos size: self.size BoxLayout: orientation: 'vertical' spacing: 50 Label: text: 'Window 1' font_size: 32 size_hint_y: None height: root.height - 125 GridLayout: cols: 3 row_force_default: True row_default_height: 40 col_force_default: True col_default_width: 100 spacing: 10 padding: 10 Button: text: 'Goto 2' font_size: 20 on_release: app.root.current = 'window2' root.manager.transition.direction = 'left' Button: text: 'Goto 3' font_size: 20 on_release: app.root.current = 'window3' root.manager.transition.direction = 'left' Button: text: 'Play Video' font_size: 20 on_release: app.root.current = 'video_window' root.manager.transition.direction = 'down' <Window2>: name: 'window2' canvas.before: Color: rgba: (10/255, 150/255, 330/255, 1) Rectangle: pos: self.pos size: self.size BoxLayout: orientation: 'vertical' size: root.width, root.height Label: text: 'Window 2' font_size: 32 size_hint_y: None height: root.height - 125 GridLayout: cols: 3 row_force_default: True row_default_height: 40 col_force_default: True col_default_width: 100 spacing: 10 padding: 10 Button: text: 'Goto 1' font_size: 20 on_release: app.root.current = 'window1' root.manager.transition.direction = 'right' Button: text: 'Goto 3' font_size: 20 on_release: app.root.current = 'window3' root.manager.transition.direction = 'left' Button: text: 'Play Video' font_size: 20 on_release: app.root.current = 'video_window' root.manager.transition.direction = 'down' <Window3> name: 'window3' canvas.before: Color: rgba: (10/255, 90/255, 30/255, 1) Rectangle: pos: self.pos size: self.size BoxLayout: orientation: 'vertical' size: root.width, root.height Label: text: 'Window 3' font_size: 32 size_hint_y: None height: root.height - 125 GridLayout: cols: 3 row_force_default: True row_default_height: 40 col_force_default: True col_default_width: 100 spacing: 10 padding: 10 Button: text: 'Goto 1' font_size: 20 on_release: app.root.current = 'window1' root.manager.transition.direction = 'right' Button: text: 'Goto 2' font_size: 20 on_release: app.root.current = 'window2' root.manager.transition.direction = 'right' Button: text: 'Play Video' font_size: 20 on_release: app.root.current = 'video_window' root.manager.transition.direction = 'down'
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Button Plays Random .MP3 File From Folder blufacebaby 2 2,251 Feb-05-2021, 02:19 AM
Last Post: BashBedlam
  [PyQt] Embedding a Video in Video Player WhatsupSmiley 0 6,097 Jan-28-2019, 06:24 PM
Last Post: WhatsupSmiley
  set button background with image of window background gray 3 14,650 Oct-18-2017, 08:22 AM
Last Post: gray

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020