Slide 1

Slide 1 text

有線イヤホンのボ タンで動画を操作 したい Kenichiro Matohara(matoken) 1

Slide 2

Slide 2 text

南隅から参加(鹿児島の右下) 好きなLinuxディストリビューションはDebian お仕事募集 mailto:work@matohara.org Kenichiro Matohara(matoken) https://matoken.org 2

Slide 3

Slide 3 text

Bluetooth ヘッドホン/ヘッドセッ ト Bluetooth ヘッドホンのA2DP,ヘッドセットのHSP/HFP では動 画や音声の操作が可能 一時停止,音量操作等 特に離席時に一時停止,着席時に再生が便利 夏場は暑く汗もかくので有線イヤホンを利用 → ボタンを押しても何も 起こらない 有線イヤホンのボタンでも一時停止などが使いたい 3

Slide 4

Slide 4 text

Bluetooth Headset button 4

Slide 5

Slide 5 text

Wired Eyerphone button 5

Slide 6

Slide 6 text

検索してみる 例 1. Not a solution for everyone, but my earphones are single buttoned. Apparently, some of those simple earphone buttons use a kind of mic signaling mechanism that checks if mic input is "high" (see this post and this post). Using audacity, I was able to verify that clicking the button generated a characterstic peak unachievable by speech (although I haven’t tried screaming!). Looking around the internet, I came up with the following solution using sox’s rec: xorg - Earphone remote in sound jack as X input - Unix & Linux Stack Exchange #!/usr/bin/sh while true; do rec -n stat trim 0 .5 2>&1 | awk '/^Maximum amplitude/ && $3 > 0.89' | grep -q 'M' && play done 6

Slide 7

Slide 7 text

ボタンを押すとマイクからhigh が入力されるよう sox のrec コマンドで録音して大きな振幅があったらボタンが押され たと判断 playerctl play-pause コマンドで再生,一時停止をトルグするこ とで実現 が,動かない? 7

Slide 8

Slide 8 text

playerctl でmpv が認識できない プロセスはあるがplayerctl でmpv が認識できない vlcやウェブブラウザは見える $ pgrep mpv 256955 $ playerctl -l No players were found $ playerctl -l vlc $ playerctl -l brave.instance4520 8

Slide 9

Slide 9 text

version の問題? upstream はmpv に対応している CHANGELOG(changelog.Debian.gz) 見ると 2.3.1 でmpv 対応しているよう Bullseye が2.3.1 なので動くはず? sid の2.4.1 でもmpv が見えない → Version の問題ではなさそう altdesktop/playerctl: 🎧 mpris media player command- line controller for vlc, mpv, RhythmBox, web browsers, cmus, mpd, spotify and others. playerctl (2.3.1-1) unstable; urgency=medium : - Add mpv to list of controllable players 9

Slide 10

Slide 10 text

ISSUE を見る mpv の操作にはmpris plugin が必要らしい not working with mpv. · Issue #285 · altdesktop/playerctl hoyon/mpv-mpris: MPRIS plugin for mpv 10

Slide 11

Slide 11 text

Debian のmpv-mpris package bullseye-backports 以降にパッケージが存在するよう $ rmadison mpv-mpris mpv-mpris | 0.7.1-1~bpo11+1 | bullseye-backports | source, amd64, arm64, armel, armhf, mpv-mpris | 0.7.1-1~bpo11+1 | bullseye-backports-debug | source mpv-mpris | 0.7.1-1 | stable | source, amd64, arm64, armel, armhf, mpv-mpris | 0.7.1-1 | testing | source, amd64, arm64, armel, armhf, mpv-mpris | 0.7.1-1 | unstable | source, amd64, arm64, armel, armhf, mpv-mpris | 0.7.1-1 | unstable-debug | source 11

Slide 12

Slide 12 text

Debian Bullseye へのmpv-mpris 導 入 amd64 の場合Release に mpris.so があるのでそれが利用できる 次回mpv 起動時から効くようになる 若しくは bullseye-backports を有効にしてmpv-mpris パッケー ジ導入が楽そう $ mkdir -p ~/.config/mpv/scripts $ wget https://github.com/hoyon/mpv-mpris/releases/download/1.0/mpris.so -O ~/.config/mpv/scrip $ playerctl -l mpv 12

Slide 13

Slide 13 text

Debian bullseye-backports 以降での 導入 パッケージがあるのでそちらを導入 次回mpv 起動時から効くようになる $ sudo apt install mpv-mpris $ playerctl -l mpv 13

Slide 14

Slide 14 text

playerctl 利用例 プレイヤーを探す メタデータのタイトルを表示 プレイヤーを一時停止 プレイヤーを再生 プレイヤーを再生/一時停止トルグ(再生中だと一時停止,一時停止だと 再生) $ playerctl -l $ playerctl --list-all $ playerctl metadata title CentOS後継エンタープライズLinux比較! 2023-7-29 B-1 $ playerctl pause $ playerctl play $ playerctl play-pause 14

Slide 15

Slide 15 text

再生状況確認(s) 30秒戻す(-),30秒進める(+) 指定時間に移動 特定のプレイヤーの操作(-p/–player) 他 $ playerctl position 1023.474151 $ playerctl position 30- $ playerctl position 30+ $ playerctl position 90 $ playerctl --player=mpv -l $ playerctl -p vlc -l : 15

Slide 16

Slide 16 text

Usage Usage: playerctl [OPTION…] COMMAND - Controller for media players For players supporting the MPRIS D-Bus specification Help Options: -h, --help Show help options Application Options: -p, --player=NAME A comma separated list of names of players to control (defaul -a, --all-players Select all available players to be controlled -i, --ignore-player=IGNORE A comma separated list of names of players to ignore. -f, --format A format string for printing properties and metadata -F, --follow Block and append the query to output when it changes for the m -l, --list-all List the names of running players that can be controlled -s, --no-messages Suppress diagnostic messages -v, --version Print version information Available Commands: play Command the player to play pause Command the player to pause play-pause Command the player to toggle between play/pause stop Command the player to stop next Command the player to skip to the next track previous Command the player to skip to the previous track position [OFFSET][+/-] Command the player to go to the position or seek forward/backward OF volume [LEVEL][+/-] Print or set the volume to LEVEL from 0.0 to 1.0 status Get the play status of the player metadata [KEY...] Print metadata information for the current track. If KEY is passed, print only those values. KEY may be artist,title, album, or any key open [URI] Command for the player to open given URI. URI can be either file path or remote URL. loop [STATUS] Print or set the loop status. 16

Slide 17

Slide 17 text

再度script を試す #!/usr/bin/sh while true; do rec -n stat trim 0 .5 2>&1 | awk '/^Maximum amplitude/ && $3 > 0.89' | grep -q 'M' && play done 17

Slide 18

Slide 18 text

sox の導入 反応がない? sox のrec が入っていなかった(エラーなし) $ sudo apt install sox $ which rec /usr/bin/rec 18

Slide 19

Slide 19 text

動いた! sox/playerctl/mpv-mpris の導入 script の実行 有線イヤホンのボタンで再生,一時停止の切り替えが出来るようになっ た :) 19

Slide 20

Slide 20 text

問題 標準以外のマイクの場合動作しない(rec コマンドで別のマイクを指定 する必要があると思う) 再生/一時停止のみの対応 ダブルクリック等を認識させて別の動作(次のメディア,30秒巻き 戻し等)を設定することは可能(なはず) 複数ボタンのあるイヤホンを利用 マイクから大きな音が入ったら誤動作する 20

Slide 21

Slide 21 text

まとめ Bluetooth Headset/Headphone のように有線イヤホンでも再 生,一時停止操作が可能に :) 暑くても大丈夫そうなイヤホンタイプやイヤーカフ,骨伝導タイプの Bluetooth Headset/Headphone などを購入したほうがいい気 も playerctl コマンドは便利.ssh 経由でも動作するし 複数ボタンのあるイヤホンでも試してみたい 21

Slide 22

Slide 22 text

奥付 発表 2023-08- 20(sun) 発表者 利用ソフトウェア ライセンス 鹿児島Linux勉強会 2023.08(オンライン開催) Kenichiro Matohara(matoken) Asciidoctor Reveal.js CC BY 4.0 22

Slide 23

Slide 23 text

No content