Music Player Daemon/ヒントとテクニック

提供: ArchWiki
2015年7月8日 (水) 11:46時点におけるKusakata (トーク | 投稿記録)による版
ナビゲーションに移動 検索に移動

メインの記事は Music Player Daemon

ライブラリの管理

MPD はライブラリの管理は行いません。公式リポジトリbeetspicard などを使うようにしてください。

Last.fm/Libre.fm scrobbling

ノート: mpd リリース 0.18 から Last.fm の サポート は削除されましたが、mpd とは独立して scrobbling ができるクライアントが存在します。

MPD を使って曲を Last.fmLibre.fm に scrobble したい場合、いくつかの選択肢があります。

mpdas

mpdas は C++ で書かれた MPD の AudioScrobbler クライアントです。curllibmpd を使っています。mpdas は最新の AudioScrobbler プロトコル (2.0) をサポートしており、ネットワークに接続していない場合 unscrobble した再生ファイルを ~/.mpdascache にキャッシュします。

mpdasAURAUR からインストールすることができます。

mpdas の設定はとてもシンプルです。公式の README を見て下さい。/etc/mpdasrc のベーシックな例として /etc/mpdasrc が使えます。

パスワードは md5 ハッシュ形式で入力します:

echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "

mpdasmpd を一緒に自動起動するには、mpd を起動しているファイルに mpdas のエントリを追加してください (例: xinitrc):

[[ -z $(pgrep -xU $UID mpdas) ]] && mpdas &

mpdsystemd ユーザーサービスで起動している場合、mpdas も同じ方法で起動するほうが良いでしょう。以下のサービスを作成して systemctl --user で起動してください。

~/.config/systemd/user/mpdas.service
[Unit]
Description=AudoScrobbler client for MPD
After=mpd.service

[Service]
ExecStart=/usr/bin/mpdas --no-daemon

[Install]
WantedBy=default.target

mpdcron

mpdcron は MPD 用の cron のようなデーモンで、イベントに合わせてユーザーが定義したアクションを実行します。モジュールを使うことで通知を表示したり、Last.fm や Libre.fm に曲を送信したり (scrobbling)、再生した曲の統計を集めたりといった拡張が可能です。

mpdcron-gitAURAUR からインストールできます。

設定やモジュールについては公式ページを見て下さい。

mpdcronmpd を一緒に自動起動するには、mpd を起動しているファイルに mpdcron のエントリを追加してください (例: xinitrc):

[[ -z $(pgrep -xU $UID mpdcron) ]] && mpdcron &

mpdscribble

mpdscribbleAUR is a daemon available in the AUR (if you prefer, mpdscribble-gitAUR is also available). This is arguably the best alternative, because it is the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it does not need any changes to /etc at all. Visit the official website for more information.

設定例:

~/.mpdscribble/mpdscribble.conf
[mpdscribble]
 host = your mpd host # optional, defaults to $MPD_HOST or localhost
 port = your mpd port # optional, defaults to $MPD_PORT or 6600
 log = /home/YOUR_USERNAME/.mpdscribble/mpdscribble.log
 verbose = 2
 proxy = your proxy # optional, e. g. http://your.proxy:8080, defaults to none

 [last.fm]
 # last.fm section, comment if you do not use last.fm
 url = http://post.audioscrobbler.com/
 username = your last.fm username
 password = your last.fm password
 journal = /home/YOUR_USERNAME/.mpdscribble/lastfm.journal

 [libre.fm]
 # libre.fm section, comment if you do not use libre.fm
 url = http://turtle.libre.fm/
 username = your libre.fm username
 password = your libre.fm password
 journal = /home/YOUR_USERNAME/.mpdscribble/librefm.journal

Your password can also be in the form of an md5hash, but this is deprecated:

echo -n "password" | md5sum | cut -f 1 -d " "

mpdscribblempd を一緒に自動起動するには、mpd を起動しているファイルに mpdscribble のエントリを追加してください (例: xinitrc):

[[ -z $(pgrep -xU $UID mpdscribble) ]] && mpdscribble &

systemd ユーザーサービス

以下のサービスを使うことで systemd のユーザーインスタンスで mpdscribble を起動することができます。詳しくは systemd/ユーザー を見て下さい。

~/.config/systemd/user/mpdscribble.service
[Unit]
Description=MPD Scribbler
Requires=mpd.service
After=mpd.service

[Service]
ExecStart=/usr/bin/mpdscribble --no-daemon

[Install]
WantedBy=default.target

Sonata

Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata does not cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.

起動時のレジューム再生を無効化

この機能は mpd バージョン 0.16.2 から追加されました。この機能を有効にすると、たとえ mpd を停止したときに曲を再生していても、mpd は "paused" 状態で起動します。以下の行を mpd.conf に追加すれば機能が有効になります:

restore_paused "yes"

サンプル設定: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once

Why these formats? Because they are the standard format for CD audio, because ALSA on its own allows more than one program "to sound" only with dmix — which uses an inferior resampling algorithm by default — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least mpd.conf is not changed this way.

What is the downside? These settings cause everything (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 is not too great a loss.

The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential ~/.asoundrc — which MPD as its own user ignores, therefore the following should go to /etc/asound.conf:

/etc/asound.conf
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz
defaults.pcm.dmix.format S16_LE # Force 16 bits
/etc/mpd.conf
audio_output {
        type                    "alsa" # Use the ALSA output plugin.
	name			"your_custom_name" # Must be present and does not have to match the actual card name , e.g. what you have in /etc/asound.conf
        options                 "dev=dmixer"
        device                  "plug:dmix" # Both lines cause MPD to output to dmix
	format	        	"44100:16:2" # the actual format
	auto_resample		"no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.
}
ノート: MPD gives the mp3 format a special treatment at decoding: it is always put out as 24 bit. (The conversion as forced by the format line only comes after that.)

If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the dmix.format line and change the one for mpd with format to "44100:*:2".

ノート: Crossfading between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.

lirc で MPD をコントロール

lircd と MPD の間を取り持つように作られたクライアントは既にいくつか存在しますが、実用レベルでは、機能が限られているためにあまり使い物になりません。

mpc と irexec を使用することが推奨されます。mpc はコマンドラインプレイヤーであり、コマンドを MPD に送信してすぐに終了するので (lirc に含まれているコマンド実行プログラムである) irexec にはうってつけです。irexec はリモコンのボタンが押されたのを受信すると指定されたコマンドを実行します。

まず最初に LIRC の記事を参照してリモコンをセットアップしてください。

lirc のスタートアップ設定ファイルを編集して下さい、デフォルトの設定ファイルの場所は ~/.lircrc です。

以下のパターンをファイルに記述します:

begin
     prog = irexec
     button = <button_name>
     config = <command_to_run>
     repeat = <0 or 1>
end

例:

## irexec
begin
     prog = irexec
     button = play_pause
     config = mpc toggle
     repeat = 0
end

begin
     prog = irexec
     button = stop
     config = mpc stop
     repeat = 0
end
begin
     prog = irexec
     button = previous
     config = mpc prev
     repeat = 0
end
begin
     prog = irexec
     button = next
     config = mpc next
     repeat = 0
end
begin
     prog = irexec
     button = volup
     config = mpc volume +2
     repeat = 1
end
begin
     prog = irexec
     button = voldown
     config = mpc volume -2
     repeat = 1
end
begin
     prog = irexec
     button = pbc
     config = mpc random
     repeat = 0
end
begin
     prog = irexec
     button = pdvd
     config = mpc update
     repeat = 0
end
begin
     prog = irexec
     button = right
     config = mpc seek +00:00:05
     repeat = 0
end
begin
     prog = irexec
     button = left
     config = mpc seek -00:00:05
     repeat = 0
end
begin
     prog = irexec
     button = up
     config = mpc seek +1%
     repeat = 0
end
begin
     prog = irexec
     button = down
     config = mpc seek -1%
     repeat = 0
end

mpc には複数の機能が存在します。詳しくは man mpc を実行してください。

PulseAudio

ローカル (通常のユーザーを使用)

特殊なオプションは必要ありません。mpd の設定ファイルのコメントに書かれているように pulse アウトプットを追加するだけです。

ローカル (特別な mpd ユーザーを使用)

When run as its own user as per the wiki instructions, mpd will be unable to send sound to another user's pulseaudio server. Rather than setting up pulseaudio as a system-wide daemon, a practice strongly discouraged by upstream, you can instead configure mpd to use pulseaudio's tcp module to send sound to localhost:

First, uncomment the tcp module in /etc/pulse/default.pa or $XDG_CONFIG_HOME/default.pa (typically ~/.config/pulse/default.pa) and set 127.0.0.1 as an allowed IP address; the home directory takes precedence:

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
#load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
#load-module module-zeroconf-publish

Additional IP ranges in cidr notation may be added using ; as the separator. Once this is complete, restart pulseaudio:

$ pulseaudio --kill
$ pulseaudio --start -or- start-pulseaudio-x11/kde

Next, edit /etc/mpd.conf and add a new pulse output pointing to 127.0.0.1 as a "remote" server:

audio_output {
       type		"pulse"
       name		"Local Music Player Daemon"
       server		"127.0.0.1"
}

Once this is added, restart mpd.

Enable the output in mpd; you should now have a working local mpd, usable by all users whose pulseaudio servers allow sound from 127.0.0.1.

リモート

As with any PulseAudio-enabled program, mpd can send sound over the network. The complete PulseAudio system is not required on the server running mpd; libpulse is the only requirement to act as a source and is already a dependency of mpd.

In order to send audio from mpd to another computer follow the directions above, editing /etc/mpd.conf on the server running mpd using the IP address of the target computer and /etc/pulse/default.pa or $XDG_CONFIG_HOME/default.pa (typically ~/.config/pulse/default.pa) on the target computer using the IP address of the server.

Once this is done, the server's mpd source should show up on the target computer while playing or paused as a normal source able to be rerouted and controlled as usual; there will be no visible source on the target while mpd is stopped.

Cue ファイル

mpd 0.17 から cue のサポートに特別な設定は必要なくなりました。MPD にはパーサーが組み込まれており、外部の cue シートも、埋め込まれている cue シートも使うことができます。例えば、mpc load albumx/x.cue コマンドで music_directory/albumx/x.cue ファイルがプレイリストとしてロードされます。CUESHEET タグの場合、mpc load albumx/x.flac

CUE ファイルのクライアントサポートはやや制限があります。CUE ファイルをサポートしているプログラムとして cantatancmpcpp があります。

HTTP ストリーミング

バージョン 0.15 から MPD には HTTP ストリーミングデーモン/サーバーが付属するようになりました。このサーバーを有効にするには mpd.conf で以下のアウトプットデバイスを設定してください:

audio_output {    
	type		"httpd"    
	name		"My HTTP Stream"
	encoder		"vorbis"		# optional, vorbis or lame
	port		"8000"
#	quality		"5.0"			# do not define if bitrate is defined
	bitrate		"128"			# do not define if quality is defined
	format		"44100:16:1"
}

好きな音楽プレイヤーで mpd サーバーの URL (と指定のポート) を開くことでこのストリームを試聴することができます。

ノート: URL に適切なファイル拡張子を含めて、ストリームのファイル形式を指定する必要がある場合があります。例えば、Winamp 5.5 を使用する場合、http://192.168.1.2:8000/ の代わりに http://192.168.1.2:8000/mpd.ogg を使います。

mpd を使って他のコンピューターのストリームに接続するには:

mpc add http://192.168.1.2:8000