简介

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

mdp 及ncmpcpp 安装

osx 平台下可以使用 brew 命令进行快速安装, 以下命令可以搜索当前本地仓库是否有以上两个应用程序.


➜ brew search mpd
==> Formulae
bandcamp-dl libmpdclient mpdas mpdscribble rtmpdump mpw mad
libmpd mpd mpdecimal mpdviz mpc mpv
==> Casks
cisdem-pdf-converter-ocr cisdem-pdfmanagerultimate kmbmpdc ➜ brew search ncmpcpp
==> Formulae
ncmpcpp ncmpc

如果仓库中不存在以上程序, 可以使用 brew update 命令更新仓库索引.

使用 brew install 命令安装, 稍待片刻后安装完成后就可以使用 mpd 及 ncmpcpp :

➜  brew install mpd ncmpcpp
Updating Homebrew...

配置 mpd

在启动 mpd 之前, 我们需要 mpd 对进行一些配置.

创建 mdp 媒体文件夹

$ 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, 用于配置 mpd 进程.

$ cat ~/.mpd/mpd.conf

music_directory "~/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"
user "guoxiangxun" # 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

创建 ncmpcpp 配置文件夹

$ mkdir ~/.ncmpcpp/
$ touch ~/.ncmpcpp/error.log

创建 config 配置文件

$ cat ~/.ncmpcpp/config

# Files
mpd_music_dir = "~/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 后台进程, 执行以下命令

mpd

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

mpd --kill

更新 mpd , 执行以下命令

mpd update

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

ncmpcpp

ncmpcpp 快捷键

  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 文件如下:

#!/usr/bin/env bash
# Print a simple line of NP in mpd. # Rolling anything what you want.
# arg1: text to roll.
# arg2: max length to display.
# arg3: roll speed in characters per second.
roll_stuff() {
local stuff="$1" # Text to print
if [ -z "$stuff" ]; then
return;
fi
local max_len="10" # Default max length.
if [ -n "$2" ]; then
max_len="$2"
fi
local speed="1" # Default roll speed in chars per second.
if [ -n "$3" ]; then
speed="$3"
fi
# Anything starting with 0 is an Octal number in Shell,C or Perl,
# so we must explicityly state the base of a number using base#number
local offset=$((10#$(date +%s) * ${speed} % ${#stuff}))
# Truncate stuff.
stuff=${stuff:offset}
local char # Character.
local bytes # The bytes of one character.
local index
for ((index=0; index < max_len; index++)); do
char=${stuff:index:1}
bytes=$(echo -n $char | wc -c)
# The character will takes twice space
# of an alphabet if (bytes > 1).
if ((bytes > 1)); then
max_len=$((max_len - 1))
fi
done
stuff=${stuff:0:max_len}
#echo "index=${index} max=${max_len} len=${#stuff}"
# How many spaces we need to fill to keep
# the length of stuff that will be shown?
local fill_count=$((${index} - ${#stuff}))
for ((index=0; index < fill_count; index++)); do
stuff="${stuff} "
done
echo "${stuff}"
} trim_method="roll" # Can be {trim or roll).
max_len=40 # Trim output to this length.
roll_speed=2 # Roll speed in chraacters per second. np=$(ncmpcpp --current-song="{{{%a - }%t}}|{%f}") if [ -n "$np" ]; then
case "$trim_method" in
"roll")
np=$(roll_stuff "${np}" ${max_len} ${roll_speed})
;;
"trim")
np=$(echo "${np}" | cut -c1-"$max_len")
;;
esac
echo "♫ ${np}"
fi
exit 0

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


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即可

osx安装mpd和ncmpcpp的更多相关文章

  1. Mac OSX 安装qemu

    参考: Installing QEMU on OS X Homebrew Mac OSX 安装qemu 1.Install Homebrew: /usr/bin/ruby -e "$(cur ...

  2. 【mac osx安装opencv,python总结】

    在macosx下安装opencv,最大的困难在于协调python版本.由于在opencv官网上,强烈建议安装完整版的python(不建议使用mac 内置的python),所以会碰到这个多个python ...

  3. 用createinstallmedia创建可恢复的OSX安装DMG

    准备 从App Store下载OS X安装程序,下载完成,会在应用程序目录 /Applications 下找到类似 Install OS X 10.xxxxxx.app(中文名如:安装 OS X 10 ...

  4. OSX安装Mysql8.0

    OSX下MySQL的安装非常方便,可以通过官网的dmg包进行安装,也可通过brew进行安装.以下介绍如何通过brew如何安装MySQL. 0X00.安装前的准备 既然要通过brew安装,那么就需要确保 ...

  5. mac osx 安装redis扩展

    1 php -v查看php版本 2 brew search php|grep redis 搜索对应的redis   ps:如果没有brew 就根据http://brew.sh安装 3 brew ins ...

  6. Mac osx 安装PIL出现Some externally hosted files were ignored (use --allow-external PIL to allow).

    出现这个问题Some externally hosted files were ignored (use --allow-external PIL to allow)的主要原因是PIL的一些依赖库还没 ...

  7. HBase Mac OSX 安装笔记

    本次测试安装的机器为Mac Book Pro, 系统为 OS X 10.9.4.hbase版本0.98.6.1. 使用Java版本为Oracle的JDK 1.6.0_65. 1. 下载安装 hbase ...

  8. Mac OSX 安装nvm(node.js版本管理器)

    我的系统 1.打开github官网https://github.com/,输入nvm搜索,选择creationix/nvm,打开 2.找到Install script,复制 curl -o- http ...

  9. Hadoop Mac OSX 安装笔记

    本次测试安装的机器为Mac Book Pro, 系统为 OS X 10.9.4.Hadoop版本2.4.1. 使用Java版本为Oracle的JDK 1.6.0_65. 1. 下载安装 Hadoop2 ...

  10. Mac OSX 安装Python的paramiko模块经验总结

    一.简单介绍 最近需要用Python模拟登录远程服务器并自动执行一些代码,需要安装一个叫paramiko的模块. paramiko官方介绍遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接 ...

随机推荐

  1. Aspose.Cells实现excel预览

    ​ 在WEB项目中经常遇到excel文档在线预览的需求,基本的解决思路有以下几大类:excel文档转PDF.excel文档直接转html.后台读取excel数据返回给前端利用Excel效果的表格插件如 ...

  2. Python: 你所不知道的星号 * 用法

    以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「englyf」https://mp.weixin.qq.com/s/FHyosiG_tegF5NRUEs7UdA 本文大概 1193 个 ...

  3. Docker定时删除none镜像

    在使用docker的时候会产生none镜像文件,偶尔没什么,但是比如使用了自动化部署工具那就不一样了,一天没准就上百个none镜像了,非常消耗资源,所以需要定时清理 删除 none 镜像命令 dock ...

  4. 【每日一题】【暴力、动态规划、动规优化、贪心】2022年1月21日-NC19 连续子数组的最大和/最大子序和

    同:最大子序和 https://www.cnblogs.com/liujinhui/p/15574312.html 描述输入一个长度为n的整型数组array,数组中的一个或连续多个整数组成一个子数组. ...

  5. Py2neo:一种快速导入百万数据到Neo4j的方式

    Py2neo:一种快速导入百万数据到Neo4j的方式 Py2neo是一个可以和Neo4j图数据库进行交互的python包.虽然py2neo操作简单方便,但是当节点和关系达几十上百万时,直接创建和导入节 ...

  6. echarts柱状图渐变色并且显示数据及柱状图的宽度调整

    series: [{ type: 'bar', name: '起飞', barWidth: '20px', //柱状图的宽度 itemStyle: { normal: { //显示渐变色颜色 colo ...

  7. 使用JsonConverter处理上传文件的路径

    场景 我们上传一个文件,把文件保存到服务器上,会有一个明确的物理路径,由于需要从前端访问这个文件,还需要web服务器中的一个虚拟路径.这个虚拟路径的存储会有一个问题,我们应该在数据库里存什么?是带域名 ...

  8. AcWing1137. 选择最佳线路

    题目传送门 题目大意 \(\qquad\)有一张有向图,可以有若干个起点,只有一个终点,求所有起点到终点的最短路中最短的一条,若所有起点都与终点不连通,则输出\(-1\) 解题思路 \(\qquad\ ...

  9. JavaScript:箭头函数:作为参数进行传参

    之前已经说过,JS的函数,也是对象,而函数名是一个变量,是可以进行传参的,也即函数是可以被传参的. 只要是函数,都可以被传参,但是箭头函数的语法更为灵活,所以更方便进行传参. 如上图所示,fun1是一 ...

  10. 使用腾讯云部署war包

    目录 1.前期准备 2.springboot打war包 3.部署war包 4.导入数据库 5.修改Tomcat启动端口 6.启动服务器 7.设置腾讯云服务器防火墙规则 8.从外部访问 9.总结 10. ...