-
-
Save dae/8e1bd93648d4ed434b22c2c06e88a051 to your computer and use it in GitHub Desktop.
Separate player for videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py | |
index 08f5c206f..32ccefce3 100644 | |
--- a/qt/aqt/sound.py | |
+++ b/qt/aqt/sound.py | |
@@ -70,6 +70,21 @@ class Player(ABC): | |
def shutdown(self) -> None: | |
"Do any cleanup required at program termination. Optional." | |
+AUDIO_EXTENSIONS = { | |
+ "wav", | |
+ "mp3", | |
+ "ogg", | |
+ "flac", | |
+ "m4a", | |
+ "3gp", | |
+ "spx", | |
+ "oga", | |
+} | |
+ | |
+def is_audio_file(fname: str) -> bool: | |
+ (base, ext) = os.path.splitext(fname) | |
+ return ext[1:].lower() in AUDIO_EXTENSIONS | |
+ | |
class SoundOrVideoPlayer(Player): # pylint: disable=abstract-method | |
default_rank = 0 | |
@@ -80,6 +95,24 @@ class SoundOrVideoPlayer(Player): # pylint: disable=abstract-method | |
else: | |
return None | |
+class SoundPlayer(Player): # pylint: disable=abstract-method | |
+ default_rank = 0 | |
+ | |
+ def rank_for_tag(self, tag: AVTag) -> Optional[int]: | |
+ if isinstance(tag, SoundOrVideoTag) and is_audio_file(tag.filename): | |
+ return self.default_rank | |
+ else: | |
+ return None | |
+ | |
+class VideoPlayer(Player): # pylint: disable=abstract-method | |
+ default_rank = 0 | |
+ | |
+ def rank_for_tag(self, tag: AVTag) -> Optional[int]: | |
+ if isinstance(tag, SoundOrVideoTag) and not is_audio_file(tag.filename): | |
+ return self.default_rank | |
+ else: | |
+ return None | |
+ | |
# Main playing interface | |
########################################################################## | |
@@ -290,7 +323,7 @@ class SimpleProcessPlayer(Player): # pylint: disable=abstract-method | |
cb() | |
-class SimpleMpvPlayer(SimpleProcessPlayer, SoundOrVideoPlayer): | |
+class SimpleMpvPlayer(SimpleProcessPlayer, VideoPlayer): | |
args, env = _packagedCmd( | |
[ | |
"mpv", | |
@@ -320,7 +353,7 @@ class SimpleMplayerPlayer(SimpleProcessPlayer, SoundOrVideoPlayer): | |
########################################################################## | |
-class MpvManager(MPV, SoundOrVideoPlayer): | |
+class MpvManager(MPV, SoundPlayer): | |
if not isLin: | |
default_argv = MPVBase.default_argv + [ | |
@@ -657,6 +690,7 @@ def setup_audio(taskman: TaskManager, base_folder: str) -> None: | |
if mpvManager is not None: | |
av_player.players.append(mpvManager) | |
+ av_player.players.append(SimpleMpvPlayer(taskman, base_folder)) | |
else: | |
mplayer = SimpleMplayerSlaveModePlayer(taskman) | |
av_player.players.append(mplayer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment