Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement audio playback by setting force-window property #161

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Macast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
import sys
import logging
from distutils.spawn import find_executable

from macast import Setting, SETTING_DIR
from macast.macast import gui
from macast.utils import SettingProperty, SingleInstance, SingleInstanceException
Expand All @@ -19,8 +21,10 @@ def get_base_path(path="."):


def set_mpv_default_path():
mpv_path = 'mpv'
if sys.platform == 'darwin':
mpv_path = find_executable('mpv')
if mpv_path:
pass
elif sys.platform == 'darwin':
mpv_path = get_base_path('bin/MacOS/mpv')
elif sys.platform == 'win32':
mpv_path = get_base_path('bin/mpv.exe')
Expand Down
14 changes: 14 additions & 0 deletions macast_renderer/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class ObserveProperty(Enum):
track_list = 6
speed = 7
sub = 8
file_format = 9


AudioFormat = ['m4a', 'mp3', 'wav', 'flac', 'ogg', 'mp2', 'amr']


class MPVRenderer(Renderer):
Expand Down Expand Up @@ -157,6 +161,9 @@ def set_observe(self):
self.send_command(
['observe_property', ObserveProperty.sub.value,
'sub-visibility'])
self.send_command(
['observe_property', ObserveProperty.file_format.value,
'file-format'])

self.set_media_volume(Setting.get(SettingProperty.PlayerDefaultVolume, 100))

Expand Down Expand Up @@ -212,6 +219,13 @@ def update_state(self, res):
data = res.get('data', None)
if data is not None:
self.set_state_subtitle(data)
elif res['id'] == ObserveProperty.file_format.value:
data = res.get('data', None)
fmts = data.split(',')
for fmt in fmts:
if fmt.lower() in AudioFormat:
self.send_command(['set_property', 'force-window', 'yes'])
break
elif 'event' in res:
logger.info(res)
if res['event'] == 'end-file':
Expand Down