Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

有線イヤホンのボタンで動画を操作したい

 有線イヤホンのボタンで動画を操作したい

source:: https://gitlab.com/matoken/kagolug-2023.08/-/blob/main/slide/slide.adoc
発表:: 鹿児島Linux勉強会 2023.08(オンライン開催) 2023-08-20(sun) https://kagolug.connpass.com/event/290544/

Kenichiro MATOHARA

August 20, 2023
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. 検索してみる 例 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
  2. 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
  3. ISSUE を見る mpv の操作にはmpris plugin が必要らしい not working with mpv.

    · Issue #285 · altdesktop/playerctl hoyon/mpv-mpris: MPRIS plugin for mpv 10
  4. 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
  5. 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
  6. playerctl 利用例 プレイヤーを探す メタデータのタイトルを表示 プレイヤーを一時停止 プレイヤーを再生 プレイヤーを再生/一時停止トルグ(再生中だと一時停止,一時停止だと 再生) $ playerctl

    -l $ playerctl --list-all $ playerctl metadata title CentOS後継エンタープライズLinux比較! 2023-7-29 B-1 $ playerctl pause $ playerctl play $ playerctl play-pause 14
  7. 再生状況確認(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
  8. 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
  9. 再度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