Skip to content

Commit

Permalink
Merge pull request open-dynaMIX#4 from open-dynaMIX/develop
Browse files Browse the repository at this point in the history
Use a more generic way to handle audio-devices for cycling
  • Loading branch information
open-dynaMIX authored Jan 16, 2019
2 parents 5b67ef6 + cb93994 commit 412e441
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
77 changes: 68 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,70 @@ You can access the webui when accessing [http://127.0.0.1:8080](http://127.0.0.1
By default it listens on `0.0.0.0:8080` and `[::0]:8080`. As described below, this can be changed.

### Options
- `--script-opts=webui-port=${PORT}`: Set the port to serve the webui (default: 8080)
- `--script-opts=webui-ipv4=no`: Disable listening on ipv4 (default: yes)
- `--script-opts=webui-ipv6=no`: Disable listening on ipv6 (default: yes)
- `--script-opts=webui-disable=yes`: Disable webui (default: no)
- `--script-opts=webui-logging=yes`: Log requests in terminal (default: no)
Options can be set with [--script-opts](https://mpv.io/manual/master/#options-script-opts)
with the prefix `webui-`.

#### port (int)
Set the port to serve the webui (default: 8080). Setting this allows for
running multiple instances on different ports.

Example:

```
webui-port=8000
```

#### ipv4 (bool)
Enable listening on ipv4 (default: yes)

Example:

```
webui-ipv4=no
```

#### ipv6 (bool)
Enable listening on ipv6 (default: yes)

Example:

```
webui-ipv6=no
```

#### disable (bool)
Disable webui (default: no)

Example:

```
webui-disable=yes
```

#### logging (bool)
Log requests in to STDOUT (default: no)

Example:

```
webui-logging=yes
```

#### audio-devices (string)
Set the audio-devices used for cycling. By default it uses all interfaces MPV
knows of.

You can see a list of them with following command:

```shell
mpv --audio-device=help
```

Example:

```
webui-audio-devices="pulse/alsa_output.pci-0000_00_1b.0.analog-stereo pulse/alsa_output.pci-0000_00_03.0.hdmi-stereo"
```

### Authentication
There is a very simple implementation of
Expand All @@ -36,15 +95,15 @@ Only plaintext `.htpasswd` entries are supported.
- [luasocket](https://github.com/diegonehab/luasocket)

## Screenshots
![screenshot](screenshots/webui.png#2)
![webui screenshot](screenshots/webui.png#2)

![screenshot](screenshots/playlist.png#1)
![playlist screenshot](screenshots/playlist.png#1)

## Media Session API
When using a browser that supports it, simple-mpv-webui uses the Media Session
API to provide a notification with some metadata and controls:

![notification](screenshots/notification.png#1)
![notification screenshot](screenshots/notification.png#1)

In order to have the notification work properly you need to at least once trigger play from the webui.

Expand All @@ -71,7 +130,7 @@ You can also directly talk to the endpoints:
| /api/set_audio_delay/:ms | POST | `int` or `float` (can be negative) | Set audio delay to :ms milliseconds |
| /api/cycle_sub | POST | | Cycle trough available subtitles |
| /api/cycle_audio | POST | | Cycle trough available audio tracks |
| /api/cycle_audio_device | POST | | Cycle trough audio devices. This is hardcoded to `alsa` and `alsa/hdmi` |
| /api/cycle_audio_device | POST | | Cycle trough audio devices. [More information.](#audio-devices-string) |

All POST endpoints return a JSON message. If successful: `{"message": "success"}`, otherwise, the message will contain
information about the error.
Expand Down
1 change: 0 additions & 1 deletion webui-page/webui.css
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ table.playlist {
cursor: pointer;
}


table.playlist.playing {
cursor: auto;
}
Expand Down
9 changes: 8 additions & 1 deletion webui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local options = {
logging = false,
ipv4 = true,
ipv6 = true,
audio_devices = '',
}
read_options(options, "webui")

Expand Down Expand Up @@ -135,7 +136,7 @@ local commands = {
end,

cycle_audio_device = function()
return pcall(mp.command, "cycle_values audio-device alsa alsa/hdmi")
return pcall(mp.command, "cycle_values audio-device " .. options.audio_devices)
end
}

Expand Down Expand Up @@ -431,6 +432,12 @@ local function init_servers()
return servers
end

if options.audio_devices == '' then
for _, device in pairs(mp.get_property_native("audio-device-list")) do
options.audio_devices = options.audio_devices .. ' ' .. device['name']
end
end

if options.disable then
mp.osd_message(msg_prefix.."disabled", 2)
return
Expand Down

0 comments on commit 412e441

Please sign in to comment.