-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--[[ | ||
An mpv script that allows switching between playing one or two audio tracks simultaneously upon file load or with a hotkey. | ||
Note that the file must have exactly two audio tracks for this script to activate, otherwise the file will be ignored. | ||
This script overrides user defiend `lavfi-complex` behavior. | ||
To set a keybind, add `{key} script-message switch-both-audio` line to your `input.conf` e.g: | ||
`n script-message switch-both-audio` | ||
To switch the default state to "on" upon opening a file, create `switch_both_audio.conf` file in `portable_config/script-opts` directory | ||
and add `enabled_on_start=yes` line to it. | ||
--]] | ||
|
||
require 'mp.options' | ||
local mp = require 'mp' | ||
local state = 'off' | ||
local options = { | ||
enabled_on_start = false, | ||
} | ||
read_options(options,nil) | ||
|
||
local function switch_on() | ||
mp.set_property('lavfi-complex', '[aid1] [aid2] amix [ao]') | ||
mp.set_property('aid','no') | ||
state = 'on' | ||
end | ||
|
||
local function switch_off() | ||
mp.set_property('lavfi-complex', '') | ||
mp.set_property_number('aid', 1) | ||
state = 'off' | ||
end | ||
|
||
local function switch_state() | ||
if state == 'off' then | ||
switch_on() | ||
elseif state == 'on' then | ||
switch_off() | ||
end | ||
end | ||
|
||
local function on_load() | ||
mp.unregister_script_message('switch-both-audio') -- prevent errors in mixed playlists by always disabling first | ||
local tracks_num = 0 | ||
for _, track in pairs(mp.get_property_native('track-list')) do | ||
if track.type == 'audio' then | ||
tracks_num = tracks_num + 1 | ||
end | ||
end | ||
|
||
if tracks_num == 2 then | ||
if options.enabled_on_start then | ||
switch_on() | ||
end | ||
mp.register_script_message('switch-both-audio', switch_state) | ||
end | ||
end | ||
|
||
mp.register_event('start-file', switch_off) -- prevent errors in mixed playlists by always disabling first | ||
mp.register_event('file-loaded', on_load) |