在你的 Fedora 终端上播放音乐
音乐
![](/data/attachment/album/202002/20/102016cacz6aabazpsqblf.png)


MPD（Music Playing Daemon），顾名思义，是一个音乐（Music）播放（Playing）守护进程（Daemon）。它可以播放音乐，并且作为一个守护进程，任何软件都可以与之交互并播放声音，包括一些 CLI 客户端。


其中一个被称为 `ncmpcpp`，它是对之前 `ncmpc` 工具的改进。名字的变化与编写它们的语言没有太大关系：都是 C++，而之所以被称为 `ncmpcpp`，因为它是 “NCurses Music Playing Client Plus Plus”。 缘故


### 安装 MPD 和 ncmpcpp


`ncmpmpcc` 的客户端可以从官方 Fedora 库中通过 `dnf` 命令直接安装。



```
$ sudo dnf install ncmpcpp
```

另一方面，MPD 必须从 RPMFusion free 库安装，你可以通过运行：



```
$ sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
```

然后你可以运行下面的命令安装它：



```
$ sudo dnf install mpd
```

### 配置并启用 MPD


设置 MPD 最简单的方法是以普通用户的身份运行它。默认情况是以专用 `mpd` 用户的身份运行它，但这会导致各种权限问题。


在运行它之前，我们需要创建一个本地配置文件，允许我们作为普通用户运行。


首先在 `~/.config` 里创建一个名叫 `mpd` 的目录:



```
$ mkdir ~/.config/mpd
```

将配置文件拷贝到此目录下:



```
$ cp /etc/mpd.conf ~/.config/mpd
```

然后用 `vim`、`nano` 或 `gedit` 之类的软件编辑它:



```
$ nano ~/.config/mpd/mpd.conf
```

我建议你通读所有内容，检查是否有任何需要做的事情，但对于大多数设置你都可以删除，只需保留以下内容：



```
db_file "~/.config/mpd/mpd.db"
log_file "syslog"
```

现在你可以运行它了：



```
$ mpd
```

没有报错，这将在后台启动 MPD 守护进程。


### 使用 ncmpcpp


只需运行：



```
$ ncmpcpp
```

你将在终端中看到一个由 ncurses 所支持的图形用户界面。


按下 `4` 键，然后就可以看到本地的音乐目录，用方向键进行选择并按下回车进行播放。


多播放几个歌曲就会创建一个*播放列表*，让你可以使用 `>` 键（不是右箭头, 是右尖括号）移动到下一首，并使用 `<` 返回上一首。`+` 和 `–` 键可以调节音量。`Q` 键可以让你退出 `ncmpcpp` 但不停止播放音乐。你可以按下 `P` 来控制暂停和播放。


你可以按下 `1` 键来查看当前播放列表（这是默认的视图）。从这个视图中，你可以按 `i` 查看有关当前歌曲的信息（标签）。按 `6` 可更改当前歌曲的标签。


按 `\` 按钮将在视图顶部添加（或删除）信息面板。在左上角，你可以看到如下的内容：



```
[------]
```

按下 `r`、`z`、`y`、`R`、`x` 将会分别切换到 `repeat`、`random`、`single`、`consume` 和 `crossfade` 等播放模式，并将这个小指示器中的 `–` 字符替换为选定模式。


按下 `F1` 键将会显示一些帮助文档，包含一系列的键绑定列表，因此无需在此处列出完整列表。所以继续吧！做一个极客，在你的终端上播放音乐！




---


via: <https://fedoramagazine.org/playing-music-on-your-fedora-terminal-with-mpd-and-ncmpcpp/>


作者：[Carmine Zaccagnino](https://fedoramagazine.org/author/carzacc/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[chai-yuan](https://github.com/chai-yuan) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
MPD, as the name implies, is a Music Playing Daemon. It can play music but, being a daemon, any piece of software can interface with it and play sounds, including some CLI clients.

One of them is called *ncmpcpp*, which is an improvement over the pre-existing *ncmpc* tool. The name change doesn’t have much to do with the language they’re written in: they’re both C++, but *ncmpcpp* is called that because it’s the *NCurses Music Playing Client* *Plus Plus*.

## Installing MPD and ncmpcpp

The *ncmpmpcc* client can be installed from the official Fedora repositories with DNF directly with

$ sudo dnf install ncmpcpp

On the other hand, MPD has to be installed from the RPMFusion *free* repositories, which you can enable, [as per the official installation instructions](https://rpmfusion.org/Configuration), by running

$ sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm

and then you can install MPD by running

$ sudo dnf install mpd

## Configuring and Starting MPD

The most painless way to set up MPD is to run it as a regular user. The default is to run it as the dedicated *mpd* user, but that causes all sorts of issues with permissions.

Before we can run it, we need to create a local config file that will allow it to run as a regular user.

To do that, create a subdirectory called *mpd* in *~/.config*:

$ mkdir ~/.config/mpd

copy the default config file into this directory:

$ cp /etc/mpd.conf ~/.config/mpd

and then edit it with a text editor like *vim*, *nano* or *gedit*:

$ nano ~/.config/mpd/mpd.conf

I recommend you read through all of it to check if there’s anything you need to do, but for most setups you can delete everything and just leave the following:

db_file "~/.config/mpd/mpd.db" log_file "syslog"

At this point you should be able to just run

$ mpd

with no errors, which will start the MPD daemon in the background.

## Using ncmpcpp

Simply run

$ ncmpcpp

and you’ll see a ncurses-powered graphical user interface in your terminal.

Press *4* and you should see your local music library, be able to change the selection using the arrow keys and press *Enter* to play a song.

Doing this multiple times will create a *playlist*, which allows you to move to the next track using the *>* button (not the right arrow, the *>* closing angle bracket character) and go back to the previous track with *<*. The + and – buttons increase and decrease volume. The *Q* button quits ncmpcpp but it doesn’t stop the music. You can play and pause with *P*.

You can see the current playlist by pressing the *1* button (this is the default view). From this view you can press *i* to look at the information (tags) about the current song. You can change the tags of the currently playing (or paused) song by pressing *6*.

Pressing the \ button will add (or remove) an informative panel at the top of the view. In the top left, you should see something that looks like this:

[------]

Pressing the *r*, *z*, *y*, *R*, *x* buttons will respectively toggle the *repeat*, *random*, *single*, *consume* and *crossfade* playback modes and will replace one of the *–* characters in that little indicator to the initial of the selected mode.

Pressing the *F1* button will display some help text, which contains a list of keybindings, so there’s no need to write a complete list here. So now go on, be geeky, and play all your music from your terminal!

## Paul

Thanks, I’ll give it a try, still prefer MOC for music on console 🙂

## Foo

Cmus is the best player.

## Andy Mender

I second this :).

## Jonny

Cmus was my go to player before I switched full time to mpd / ncmpcpp. Never looked back because life has just been easier….

## dac.override

Long time user of mpc and ncmpc here. I recently rediscovered Emacs mpc major mode. This thing takes a bit of getting used to but I currently prefer it because you get a good oversight of your music collection. I often search for tunes based on genre, and I never really got used to doing that with ncmpc. With emacs all the available genres are in plain sight and easy to peruse.

## homme

:coffee:

## webpage

I am in fact pleased to read this webpage posts which includes

plenty of useful information, thanks for providing such statistics.

## erte

How playing i tmux?

with resize for setup and small icon ot in window no see anything?