From 4fb7014543b5ef91abfbe3e098cdb0857ea949b9 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Sun, 9 Jan 2022 19:05:11 +0100 Subject: [PATCH] Try out MPV --- dpkg.lst | 1 + requirements.txt | 2 +- src/main.py | 118 +++++++++++++++++++++++++++-------------------- 3 files changed, 71 insertions(+), 50 deletions(-) diff --git a/dpkg.lst b/dpkg.lst index cd264d1..7b12271 100644 --- a/dpkg.lst +++ b/dpkg.lst @@ -22,6 +22,7 @@ libgstreamer-plugins-bad1.0-0:amd64 libgstreamer-plugins-base1.0-0:amd64 libgstreamer-plugins-good1.0-0:amd64 libgstreamer1.0-0:amd64 +libmpv1 python3-wxgtk-media4.0 python3-wxgtk4.0 python3-feedparser diff --git a/requirements.txt b/requirements.txt index f1be8df..850b39e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ pychromecast - +python-mpv diff --git a/src/main.py b/src/main.py index e1156b0..86e73e9 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import mpv import json import os import threading @@ -271,59 +272,78 @@ class Cast(wx.Frame): """ self.m_sizer.Clear(delete_windows=True) self.m_sizer = wx.BoxSizer(wx.VERTICAL) - # self.m_sizer.AddSpacer(SPACER_HEIGHT * 4) - inner_sizer = wx.GridBagSizer() - self.m_control = wx.media.MediaCtrl( - self.m_panel, + #inner_sizer = wx.GridBagSizer() + window = wx.Window(self.m_panel, size=(WIDTH, int(HEIGHT / 2)), - style=wx.SIMPLE_BORDER, - szBackend=wx.media.MEDIABACKEND_GSTREAMER, - ) - play_button = wx.Button(self.m_panel, -1, "Play") - - pause_button = wx.Button(self.m_panel, -1, "Pause") - - back_button = wx.Button(self.m_panel, -1, "Back") - back_button.Bind( - wx.EVT_BUTTON, - lambda event, cindex=channel_index: self.show_video_list(event, cindex), - ) - - inner_sizer.Add(self.m_control, (0, 0)) - inner_sizer.SetItemSpan(0, (0, 6)) - inner_sizer.Add(play_button, (1, 1)) - inner_sizer.Add(pause_button, (1, 2)) - inner_sizer.Add(back_button, (1, 3)) - - if not self.m_chromecast_thr.is_alive( - ) and not self.m_selected_chromecast: - chromecast_button = wx.Button(self.m_panel, -1, "Cast") - chromecast_button.Bind( - wx.EVT_BUTTON, - lambda event, muri=uri, cindex=channel_index: self.select_chromecast(event, muri, cindex), - ) - inner_sizer.Add(chromecast_button, (2, 2)) - self.m_sizer.Add(inner_sizer) - - if self.m_selected_chromecast: - self.Bind( - wx.media.EVT_MEDIA_LOADED, - lambda event, muri=uri: self.cast(event, muri), - ) - play_button.Bind(wx.EVT_BUTTON, self.play_cast) - pause_button.Bind(wx.EVT_BUTTON, self.pause_cast) - else: - self.Bind(wx.media.EVT_MEDIA_LOADED, self.play) - play_button.Bind(wx.EVT_BUTTON, self.play) - pause_button.Bind(wx.EVT_BUTTON, self.pause) - - self.Bind(wx.media.EVT_MEDIA_FINISHED, lambda event: self.show_video_list(event,0)) - self.load_uri(uri) - self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True) + ) + self.m_sizer.Add(window) + player = mpv.MPV(ytdl=False,player_operation_mode='pseudo-gui', + script_opts='osc-layout=box,osc-seekbarstyle=bar,osc-deadzonesize=0,osc-minmousemove=3', + input_default_bindings=True, + input_vo_keyboard=True, + osc=True) + #player = mpv.MPV(ytdl=True, input_default_bindings=True, input_vo_keyboard=True, osc=True, wid=str(window.GetId())) self.m_panel.SetSizer(self.m_sizer) self.m_sizer.Fit(self) self.m_sizer.Layout() - self.m_panel.ScrollChildIntoView(self.m_control) + try: + player.play(uri) + player.wait_for_playback() + except mpv.ShutdownError: + player.terminate() + del player + self.show_video_list(None,0) + #self.m_control = wx.media.MediaCtrl( + # self.m_panel, + # size=(WIDTH, int(HEIGHT / 2)), + # style=wx.SIMPLE_BORDER, + # szBackend=wx.media.MEDIABACKEND_GSTREAMER, + #) + #play_button = wx.Button(self.m_panel, -1, "Play") + + #pause_button = wx.Button(self.m_panel, -1, "Pause") + + #back_button = wx.Button(self.m_panel, -1, "Back") + #back_button.Bind( + # wx.EVT_BUTTON, + # lambda event, cindex=channel_index: self.show_video_list(event, cindex), + #) + + #inner_sizer.Add(self.m_control, (0, 0)) + #inner_sizer.SetItemSpan(0, (0, 6)) + #inner_sizer.Add(play_button, (1, 1)) + #inner_sizer.Add(pause_button, (1, 2)) + #inner_sizer.Add(back_button, (1, 3)) + + #if not self.m_chromecast_thr.is_alive( + #) and not self.m_selected_chromecast: + # chromecast_button = wx.Button(self.m_panel, -1, "Cast") + # chromecast_button.Bind( + # wx.EVT_BUTTON, + # lambda event, muri=uri, cindex=channel_index: self.select_chromecast(event, muri, cindex), + # ) + # inner_sizer.Add(chromecast_button, (2, 2)) + #self.m_sizer.Add(inner_sizer) + + #if self.m_selected_chromecast: + # self.Bind( + # wx.media.EVT_MEDIA_LOADED, + # lambda event, muri=uri: self.cast(event, muri), + # ) + # play_button.Bind(wx.EVT_BUTTON, self.play_cast) + # pause_button.Bind(wx.EVT_BUTTON, self.pause_cast) + #else: + # self.Bind(wx.media.EVT_MEDIA_LOADED, self.play) + # play_button.Bind(wx.EVT_BUTTON, self.play) + # pause_button.Bind(wx.EVT_BUTTON, self.pause) + + #self.Bind(wx.media.EVT_MEDIA_FINISHED, lambda event: self.show_video_list(event,0)) + #self.load_uri(uri) + #self.m_panel.SetupScrolling(rate_y=SCROLL_RATE, scrollToTop=True) + #self.m_panel.SetSizer(self.m_sizer) + #self.m_sizer.Fit(self) + #self.m_sizer.Layout() + #self.m_panel.ScrollChildIntoView(self.m_control) def select_chromecast(self, _, uri, channel_index): self.m_sizer.Clear(delete_windows=True)