Search code examples
pythonkivykivy-language

kivy VideoPlayer: Video does not return to its original size after full screen mode


When I double click on the video, it goes full screen, but if I double click on it again, it doesn't go back to normal. However, the rest of the window elements are partially visible. The part of my .kv code responsible for the VideoPlayer is given below:

<VideosWindow>:
name: 'vids'
FloatLayout:
    FileChooserListView:
        id:chooser
        path: root.get_files_list() 
        canvas.before:
            Color:
                rgb: .4, .5, .5
            Rectangle:
                pos: self.pos
                size: self.size
                on_selection: root.select(chooser.selection)
        size_hint: (.9, .15)
        pos_hint: {'x':.05, 'y':.8} 
    VideoPlayer:
        id:vid
        options: {'eos':'loop'}
        size_hint: (.9, .7)
        pos_hint: {'x':.05, 'y':.05} 
    Button:
        size_hint_y: 0.3
        height: 48
        text: "open"
        disabled: not chooser.selection  
        on_release: root.select(chooser.selection)
        size_hint: (.45, .05)
        pos_hint: {'x':.05, 'y':.00}
    Button:
        text: 'Go Back'
        color: (1,1,1,1)
        background_normal:''
        background_color: (0.3,0.6,0.7,1)
        on_release: 
            vid.state = 'pause'
            app.root.current = 'saved_files'
        size_hint: (.45, .05)
        pos_hint: {'x':.50, 'y':.00}

VideosWindow class code:

class VideosWindow(Screen):
def get_files_list(self):
    files = os.sep.join([my_folder,'mp4'])
    return files

def select(self, filename):
    self.ids.vid.source = filename[0]
    self.ids.vid.state = 'play'

The screenshots of my program before and after I go fullscreen mode: before after


Solution

  • Solved this issue by adding VideoPlayer widget to the GridLayout. Now .kv code looks like this:

    <VideosWindow>:
    name: 'vids'
    FloatLayout:
        FileChooserListView:
            id:chooser
            path: root.get_files_list() 
            canvas.before:
                Color:
                    rgb: .4, .5, .5
                Rectangle:
                    pos: self.pos
                    size: self.size
                    on_selection: root.select(chooser.selection)
            size_hint: (.9, .15)
            pos_hint: {'x':.05, 'y':.8} 
    
    
        GridLayout:
            cols:1
            size_hint: (.9, .7)
            pos_hint: {'x':.05, 'y':.05} 
            VideoPlayer:
                id:vid
                options: {'eos':'loop'}      
    
          
        Button:
            size_hint_y: 0.3
            height: 48
            text: "open"
            disabled: not chooser.selection  
            on_release: root.select(chooser.selection)
            size_hint: (.45, .05)
            pos_hint: {'x':.05, 'y':.00}
        Button:
            text: 'Go Back'
            color: (1,1,1,1)
            background_normal:''
            background_color: (0.3,0.6,0.7,1)
            on_release: 
                vid.state = 'pause'
                app.root.current = 'saved_files'
            size_hint: (.45, .05)
            pos_hint: {'x':.50, 'y':.00}
    

    Don't know if it is good decision but it works.