目录

osx 安装 mpd,终端播放音乐

mdp 是一款开源的音乐播放软件, 全名为 media player daemon , 从字面意思理解, 就是一个后台播放进程. 不同于传统的音乐播放软件集成了播放解码和界面, mpd 只是一个后台播放进程, 需要单独的客户端程序与 mpd 进行交互. mpd 的客户端也各种各样, 有浏览器插件/windows 客户端/gnome 客户端/终端客户端等等

安装 mpd 和 ncmpcpp

1
brew install mpd ncmpcpp

安装完成后会提示:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
PD requires a config file to start.
Please copy it from /usr/local/etc/mpd/mpd.conf into one of these paths:
  - ~/.mpd/mpd.conf
  - ~/.mpdconf
and tailor it to your needs.

To restart mpd after an upgrade:
  brew services restart mpd
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mpd/bin/mpd --no-daemon

配置 mpd

可以去 /usr/local/etc/mpd/mpd.conf 看一下默认配置。这里,我就直接使用自己的配置啦

1
2
3
4
$ mkdir -p ~/.mpd/playlists
$ touch ~/.mpd/{mpd.conf,mpd.db,mpd.log,mpd.pid,mpdstate}
$ ls ~/.mpd/
mpd.conf mpd.db mpd.log mpd.pid mpdstate playlists

编辑 ~/.mpd/mpd.conf ,写入如下配置:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 注意这里写自己的目录,比如 ~/Music
music_directory "~/work/music"
playlist_directory "~/.mpd/playlists"
db_file "~/.mpd/mpd.db"
log_file "~/.mpd/mpd.log"
log_level "default"
# log_level "verbose"
pid_file "~/.mpd/mpd.pid"
state_file "~/.mpd/mpdstate"
auto_update "yes"
auto_update_depth "3"
follow_outside_symlinks "yes"
follow_inside_symlinks "yes"

audio_output {
    type "osx"
        name "CoreAudio"
        mixer_type "software" # control volume localy
        # mixer_type "hardware"
}

decoder {
    plugin "mp4ff"
        enabled "no"
}

bind_to_address "127.0.0.1"
port "6600"

# Visualizer
audio_output {
    type "fifo"
        name "my_fifo"
        path "/tmp/mpd.fifo"
        format "44100:16:2"
        buffer_time "100000"
        # # auto_resample "no"
        # # use_mmap "yes"
}

安装客户端 ncmpcpp

配置

1
2
3
mkdir ~/.ncmpcpp/
touch ~/.ncmpcpp/error.log
touch ~/.ncmpcpp/config

编辑 ~~/.ncpmcpp/config~,写入如下配置:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
# Files
# 这个目录和上面的保持一致,比如 ~/Music
mpd_music_dir = "~/work/music"
lyrics_directory = ~/.ncmpcpp/lyrics
ncmpcpp_directory = ~/.ncmpcpp
mpd_host = "localhost"
mpd_port = "6600"
mpd_connection_timeout = "5"
mpd_crossfade_time = "5"

# Playlist
playlist_disable_highlight_delay = "0"
playlist_show_remaining_time = "yes"

## Display Modes ##
playlist_editor_display_mode = "columns"
search_engine_display_mode = "columns"
browser_display_mode = "columns"
playlist_display_mode = "columns"

## Song List ##
# song_columns_list_format = "(10)[blue]{l} (30)[green]{a} (30)[magenta]{b} (50)[yellow]{t}"
song_columns_list_format = "(10f)[250]{l} (50)[cyan]{t|f} (18)[blue]{a} (22)[magenta]{br}"
song_list_format = "{$3%n │ $9}{$7%a - $9}{$5%t$9}|{$8%f$9}$R{$6 │ %b$9}{$3 │ %l$9}"

## General Colors ##
colors_enabled = "yes"
main_window_color = "red"
header_window_color = "cyan"
volume_color = "red"
progressbar_color = "cyan"
statusbar_color = "red"
progressbar_elapsed_color = "white"
active_window_border = "blue"

## Current Item ##
current_item_prefix = "$(blue)$r"
current_item_suffix = "$/r$(end)"
current_item_inactive_column_prefix = "$(cyan)$r"

## Alternative Interface ##
user_interface = "alternative"
# user_interface = "classic"
alternative_header_first_line_format = "$0$aqqu$/a {$7%a - $9}{$5%t$9}|{$8%f$9} $0$atqq$/a$9"
alternative_header_second_line_format = "{{$6%b$9}{ [$6%y$9]}}|{%D}"

# visualizer
# # visualizer_fifo_path = "/tmp/mpd.fifo" # deprecated , using visualizer_data_source
visualizer_data_source = "/tmp/mpd.fifo"
visualizer_output_name = "my_fifo"
# # visualizer_sync_interval = "12"  # using buffer_time in mpd.conf audio_output
visualizer_type = "wave" (spectrum/wave)
#visualizer_type = "spectrum"
visualizer_in_stereo = "yes"
visualizer_look = "+|"
# visualizer_look = "▋▋"

## Navigation ##
cyclic_scrolling = "yes"
header_text_scrolling = "yes"
jump_to_now_playing_song_at_start = "yes"
lines_scrolled = "2"

## Other ##
system_encoding = "utf-8"
regular_expressions = "extended"

## Selected tracks ##
selected_item_prefix = "* "
discard_colors_if_item_is_selected = "yes"

## Seeking ##
incremental_seeking = "yes"
#seek_time = "1"

## Visivility ##
header_visibility = "yes"
statusbar_visibility = "yes"
titles_visibility = "yes"

progressbar_look = "=>-"
#progressbar_look = "─╼─"

# ## Now Playing ##
#now_playing_prefix = "> "
now_playing_prefix = "$b$2▶ "
centered_cursor = "yes"

# ## Classic Interface ##
song_status_format = " $2%a $4⟫$3⟫ $8%t $4⟫$3⟫ $5%b "

# Misc
display_bitrate = "yes"
# enable_window_title = "no"
follow_now_playing_lyrics = "yes"
ignore_leading_the = "yes"
empty_tag_marker = ""
default_place_to_search_in = "database"
autocenter_mode = "yes"
ignore_diacritics = "yes"
allow_for_physical_item_deletion = "yes"

启动 mpd

启动 mpd 后台进程, 执行以下命令

1
mpd

关闭 mpd 后台进程, 执行以下命令

1
mpd --kill

更新 mpd , 执行以下命令

1
mpd update

在终端打开 ncmpcpp 客户端, 执行以下命令

1
ncmpcpp

ncmpcpp 快捷键

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Keys - Movement

  Up k                 : Move cursor up
  Down j               : Move cursor down
  [                    : Move cursor up one album
  ]                    : Move cursor down one album
  {                    : Move cursor up one artist
  }                    : Move cursor down one artist
  PageUp               : Page up
  PageDown             : Page down
  Home                 : Home
  End                  : End

  Tab                  : Switch to next screen in sequence
  Shift-Tab            : Switch to previous screen in sequence
  F1                   : Show help
  1                    : Show playlist
  2                    : Show browser
  3                    : Show search engine
  4                    : Show media library
  5                    : Show playlist editor
  6                    : Show tag editor
  7                    : Show outputs
  8                    : Show music visualizer
  =                    : Show clock

  @                    : Show server info

Keys - Global

  Backspace            : Play
  s                    : Stop
  p                    : Pause
  >                    : Next track
  <                    : Previous track
  Ctrl-H Backspace     : Replay current song
  f                    : Seek forward in playing song
  b                    : Seek backward in playing song
  Left -               : Decrease volume by 2%
  Right +              : Increase volume by 2%

  T                    : Toggle add mode (add or remove/always add)
  |                    : Toggle mouse support
  Ctrl-V               : Select range
  v                    : Reverse selection
  V                    : Remove selection
  Insert               : Select current item
  Ctrl-_               : Select found items
  B                    : Select songs of album around the cursor
  a                    : Add selected items to playlist
  `                    : Add random items to playlist

  r                    : Toggle repeat mode
  z                    : Toggle random mode
  y                    : Toggle single mode
  R                    : Toggle consume mode
  Y                    : Toggle replay gain mode
  #                    : Toggle bitrate visibility
  x                    : Toggle crossfade mode
  X                    : Set crossfade
                       : Set volume
  u                    : Start music database update

  :                    : Execute command
  Ctrl-F               : Apply filter
  /                    : Find item forward
  ?                    : Find item backward
  ,                    : Jump to previous found item
  .                    : Jump to next found item
  w                    : Toggle find mode (normal/wrapped)
  G                    : Locate song in browser
  ~                    : Locate song in media library
  Ctrl-L               : Lock/unlock current screen
  Left                 : Switch to master screen (left one)
  Right                : Switch to slave screen (right one)
  E                    : Locate song in tag editor
  P                    : Toggle display mode
  \                    : Toggle user interface
  !                    : Toggle displaying separators between albums
  g                    : Jump to given position in playing song (formats: mm:ss, x%)
  i                    : Show song info
  I                    : Show artist info
  F                    : Fetch lyrics for selected songs
  L                    : Toggle lyrics fetcher
  Alt-l                : Toggle fetching lyrics for playing songs in background
                       : Show/hide song lyrics

  q EoF                : Quit

Keys - Playlist

  Enter                : Play selected item
  Delete               : Delete selected item(s) from playlist
  c                    : Clear playlist
  C                    : Clear playlist except selected item(s)
  Ctrl-P               : Set priority of selected items
  m                    : Move selected item(s) up
  n                    : Move selected item(s) down
  M                    : Move selected item(s) to cursor position
  A                    : Add item to playlist
                       : Load stored playlist
  e                    : Edit song
  S                    : Save playlist
  Z                    : Shuffle range
  Ctrl-S               : Sort range
  Ctrl-R               : Reverse range
  o                    : Jump to current song
  U                    : Toggle playing song centering

Keys - Browser

  Enter                : Enter directory
  Enter                : Add item to playlist and play it
  Space                : Add item to playlist
  e                    : Edit song
  e                    : Edit directory name
  e                    : Edit playlist name
  2                    : Browse MPD database/local filesystem
  Ctrl-S               : Toggle sort mode
  o                    : Locate current song
  Ctrl-H Backspace     : Jump to parent directory
  Delete               : Delete selected items from disk
  G                    : Jump to playlist editor (playlists only)

Keys - Search engine

  Enter                : Modify option / Run action
  Space                : Add item to playlist
  Enter                : Add item to playlist and play it
  e                    : Edit song
  y                    : Start searching
  3                    : Reset search constraints and clear results

Keys - Media library

  4                    : Switch between two/three columns mode
  Left h               : Previous column
  Right l              : Next column
  Enter                : Add item to playlist and play it
  Space                : Add item to playlist
  o                    : Locate current song
  e                    : Edit song
  e                    : Edit tag (left column)/album (middle/right column)
  `                    : Toggle type of tag used in left column
  Ctrl-S               : Toggle sort mode

Keys - Playlist editor

  Left h               : Previous column
  Right l              : Next column
  Enter                : Add item to playlist and play it
  Space                : Add item to playlist
  o                    : Locate current song
  e                    : Edit song
  e                    : Edit playlist name
  m                    : Move selected item(s) up
  n                    : Move selected item(s) down
  Delete               : Delete selected playlists (left column)
  Delete               : Delete selected item(s) from playlist (right column)
  c                    : Clear playlist
  C                    : Clear playlist except selected items

Keys - Lyrics

  Space                : Toggle lyrics update on song change
  e                    : Open lyrics in external editor
  `                    : Refetch lyrics

Keys - Tiny tag editor

  Enter                : Edit tag / Run action
  y                    : Save

Keys - Tag editor

  Enter                : Enter directory (right column)
  Enter                : Perform operation on selected items (middle column)
  Enter                : Edit item (left column)
  Left h               : Previous column
  Right l              : Next column
  Ctrl-H Backspace     : Jump to parent directory (left column, directories view)

Keys - Outputs

  Enter                : Toggle output

集成 tmux

如果使用 tmux 需要在状态栏显示当前播放歌曲, 可以创建 ~/.tmux/tmux-scripts/np_mpd.sh 脚本文件, 并在 tmux.conf 中配置状态栏. np_mpd.sh 文件如下:

macos - osx安装mpd和ncmpcpp - 个人文章 - SegmentFault 思否

打开 ~/.tmux.conf 文件, 修改状态栏配置如下:

1
set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M | Mail: #(sh ~/.tmux/tmux-scripts/tmuxmail) | #(sh ~/.tmux/tmux-scripts/np_mpd.sh)'

其它问题

如果 ncmpcpp 配置无误,但就是没有音乐,进入 ncmpcpp,按下 2 或 4,选择文件(文件夹),按下 a,添加到 playlist 即可

参考

macos - osx安装mpd和ncmpcpp - 个人文章 - SegmentFault 思否

MPD:安装配置音乐播放后台进程 Music Player Daemon - 知乎

Mac 上使用 Music Player Daemon 在终端下播放音乐

GitHub - darknessomi/musicbox: 网易云音乐命令行版本

使用 mpd + mingus 听音乐 - #16,来自 Kinney - Emacs-general - Emacs China

GitHub - mpdel/mpdel: Emacs user interface for MPD

Emacs 作为 MPD 客户端 - 暗无天日