红联Linux门户
Linux帮助

Linux命令行音乐播放器moc

发布时间:2017-05-08 09:23:18来源:linux网站作者:szyk
moc(Music On Console,播放器程序是mocp,在Arch Linux的Commity中有个tray版本的moc,启动时会在面板上显示一个图标,能直接启动mocp服务和播放器。甚至还能让osdlyrics加载桌面歌词,不过这很卡.)适用于命令行,在黑乎乎的Linux核心控制台(字符界面)上也能成功启动和播放,但Linux核心控制台默认是没有中文支持的,可以试试能显示中文的fbterm(直接从核心控制台启动,不需要运行X服务)如果需要的话。即便如此,正常使用仍然需要一番手动配置才行,如果全是英文歌曲的话例外。
基本上很多的Linux发行的官方源中已经包含了这个软件包,直接使用软件包管理工具安装。Arch Linux的是pacman。
注:启动mocp之前,如果需要启用更多的音频格式支持,有必要从源上安装解码器
 
1.mocp配置
在配置mocp之前,可以先从moc的man手册页或者info页获取更多的信息(比如配置文件是什么,应该放到什么位置,格式应该是什么样的。)
$ mocp --help
$ man mocp
$ info mocp
注:
moc的aur版本允许mocp加载歌词(但仅限某些utf-8编码的ascii文本(纯英文)),这个版本会和系统中已经安装的冲突.
虽然osdlyrics理论上也支持moc,然而仅仅只是安装moc然后打开mocp再打开osdlyrics并不会加载音频文件的lyrics的(尽管这也不会导致osdlyrics退出)
要让osdlyrics真正支持moc,还要安装moc-tray这个任务栏小程序并在启动osdlyrics之前启动mocp和moc-tray.
moc-tray可以直接启动mocp并且支持停止/播放/暂停/退出,下一首/上一首等动作,不过某些动作需要在mocp中配置播放列表才能得到正确响应。
aur上的moc构建和安装:
下载PKGBUILD等makepkg需要的脚本.
$ git clone https://aur.archlinux.org/moc-lyrics-git.git
$ pushd mocp-lyrics-git
$ makepkg -sr
编译成功之后会产生一个.pkg.tar.xz包,然后使用pacman -U安装
$ mv moc-lyrics-git-1\:0.2213.c51e02e-1-x86_64.pkg.tar.xz moc-lyrics-git-x86_64.pkg.tar.xz
# pacman -U moc-lyrics-git-x86_64.pkg.tar.xz
拷贝mocp示例配置文件到~/.moc(没有就创建),参数配置可以从示例文件config.example(可以运行locate config.example)中找到
mocp的示例配置文件尽管使用了英文,但解释的很详细.
$ mkdir ~/.moc
$ cp `locate config.example` ~/.moc/config
下面这是从实例配置文件拷过来的,以#号开始的都是注释(尽管注释看起来显得晦涩难懂,但作者解释的很清楚)。
~/.moc/config
mocp User themes:
##########################################
# This is a configuration file for the MOC player. It should be named
# 'config' and placed in the ~/.moc directory. As this file can specify
# commands which invoke other applications, MOC will refuse to start if it
# is not owned by either root or the current user, or if it is writable by
# anyone other than its owner. All options are given with their default
# values, and therefore commented.
# Comments begin with '#'.
# You can use quotes and escape ('\') in parameters.
#
# You can have variable values substituted by enclosing the variable name
# as "${...}". (This only applies to the portion of the option following
# the '='.) Variables are substituted first from the environment then,
# if not found, from the configuration options. (Note that the value of
# a configuration option substituted is that which it has at the time the
# substitution variable is encountered.) If there is a naming conflict
# between an environment and configuration variable, you may be able to
# resolve it by using lowercase as the environment variable matches are
# case-sensitive whereas the configuration variables are not.
#
# You can also use the form "${...:-...}" where the value in the second
# position will be substituted if the variable name given in the first
# position is unset or null.
#
# So, for example:
#
# MusicDir = /music/${USER:-public}
# Fastdir1 = ${MusicDir}/mp3/rock
# Fastdir2 = ${MusicDir}/mp3/electronic
# Fastdir3 = ${MusicDir}/mp3/rap
# Fastdir4 = ${MusicDir}/mp3/etc
#
# Variable names are limited to those accepted by the BASH shell; that
# is, those comprising the upper- and lowercase ASCII characters, digits
# and the underscore.
#
# If you need to use the "${" sequence for any other purpose, write "$${"
# and it will be replaced by "${" and not treated as a substitution.
#
# Some options take lists of strings as their values. The strings are
# separated by colons. Additional strings can be appended to the list
# using "+=" in place of a plain "=" to assign the value. For an example,
# see the XTerms option.
#
# You can override any configuration option when you run MOC using the
# '-O' command line option:
#
# mocp -O AutoNext=no -O messagelingertime=1 -O XTerms+=xxt:xwt
#
# This command line option can be repeated as many times as needed and
# the configuration option name is not case sensitive. (Note that MOC
# does not perform variable substitution on the value of such overridden
# configuration options.) Most option values are set before the
# configuration file is processed (which allows the new values to be
# picked up by substitutions), however list-valued options are overridden
# afterwards (which gives the choice of whether the configured values are
# replaced or added to).
# Remember that the client and server are separate processes and the
# server will retain the configuration values formed from the environment
# within which it was originally started.
# Show file titles (title, author, album) instead of file names?
# 音频播放器会从音频文件中读取并在播放列表中显示音频文件媒体库元信息(包括标题,歌手,专辑等信息),Windows中的音频文件元信息(ID标签)默认和Linux使用了不同的字符集编码,因此从windows下载的音频文件可能在播放列表中很多元信息显示为乱码。不读取这些元信息只能避免在moc不显示为乱码,但并不能从根本上解决音频文件元信息显示为乱码的问题! 如果确实需要元信息正常显示,可以移步Arch wiki
ReadTags = no
# In which directory do you store your music files? If you specify it
# you will be able to jump straight to this directory with the '-m'
# parameter or the 'm' command. This can also point to a playlist.
#
# Example: MusicDir = "/home/joe/music"
#
#MusicDir =
MusicDir = /media/Others/Audio-Frequency
# Start in the music directory by default? If set to 'no', start
# in the current directory by default. A single directory on
# the command line takes precedence.
StartInMusicDir = yes
# The number of lines which are retained in an in-memory circular logging
# buffer. A value of zero indicates that lines will be written directly
# to the log file, otherwise the latest CircularLogSize lines are retained
# in memory and not written to the log file until the MOC client or server
# are shutdown. If the client or server terminates abnormally then the
# log lines are lost.
#
# This option is intended to help identify problems which occur infrequently
# and for which the amount of disk space consumed by logging would otherwise
# be a limiting factor. Obviously the memory footprint will increase in
# proportion to the value of this option.
#CircularLogSize = 0
# How to sort? FileName is the option's only value for now.
#Sort = FileName
# Show errors in the streams (for example, broken frames in MP3 files)?
#ShowStreamErrors = no
# Ignore CRC errors in MP3 files? Most players do that, so the default
# value is 'yes'.
MP3IgnoreCRCErrors = yes
# Set playback toggles.
# 设置播放标志
Repeat = yes #是否循环播放
Shuffle = yes #是否开启随机播放
AutoNext = yes #是否自动播放下一首
# Default FormatString:
#
# %n - Track number
# %a - Artist
# %A - Album
# %t - Title
# %(X:TRUE:FALSE) - Ternary expression: if X exists, do TRUE,
# otherwise FALSE. The escape character must
# be doubled (i.e., '\\'). (See zshmisc
# documentation for more information.)
#
#FormatString = "%(n:%n :) %f"
# Input and output buffer sizes (in kilobytes).
#InputBuffer = 512 # Minimum value is 32KB
#OutputBuffer = 512 # Minimum value is 128KB
# How much to fill the input buffer before playing (in kilobytes)?
# This can't be greater than the value of InputBuffer. While this has
# a positive effect for network streams, it also causes the broadcast
# audio to be delayed.
#Prebuffering = 64
# Use this HTTP proxy server for internet streams. If not set, the
# environment variables http_proxy and ALL_PROXY will be used if present.
#
# Format: HTTPProxy = PROXY_NAME:PORT
#
#HTTPProxy =
# Sound driver - OSS, ALSA, JACK, SNDIO (on OpenBSD) or null (only for
# debugging). You can enter more than one driver as a colon-separated
# list. The first working driver will be used.
#SoundDriver = JACK:ALSA:OSS
SoundDriver = ALSA:OSS:JACK
# Jack output settings.
#JackClientName = "moc"
#JackStartServer = no
#JackOutLeft = "system:playback_1"
#JackOutRight = "system:playback_2"
# OSS output settings.
#OSSDevice = /dev/dsp
#OSSMixerDevice = /dev/mixer
#OSSMixerChannel1 = pcm # 'pcm', 'master' or 'speaker'
#OSSMixerChannel2 = master # 'pcm', 'master' or 'speaker'
# ALSA output settings. If you need to dump the audio produced by MOC
# to a file for diagnostic purposes, the following setting of 'ALSADevice'
# should do that:
#
# ALSADevice=tee:hw,'/tmp/out.wav',wav
#
#ALSADevice = default
#ALSAMixer1 = PCM
ALSAMixer2 = Master
# Save software mixer state?
# If enabled, a file 'softmixer' will be created in '~/.moc/' storing the
# mixersetting set when the server is shut down.
# Note that there is a "hidden" 'Amplification' setting in that file.
# Amplification (0-200) is used to scale the mixer setting (0-100). This
# results in a higher signal amplitude but may also produce clipping.
Softmixer_SaveState = yes
# Save equalizer state?
# If enabled, a file 'equalizer' will be created in '~/.moc/' storing the
# equalizer settings when the server is shut down.
# Note that there is a "hidden" 'Mixin' setting in that file.
# Mixin (0.0-1.0) is used to determine how much of the original signal is
# used after equalizing. 0 means to only use the equalized sound, while 1
# effectively disabled the mixer. The default is 0.25.
#Equalizer_SaveState = yes
# Show files with dot at the beginning?
ShowHiddenFiles = yes
# Hide file name extensions?
HideFileExtension = yes
# Show file format in menu?
ShowFormat = no
# Show file time in menu? Possible values: 'yes', 'no' and 'IfAvailable'
# (meaning show the time only when it is already known, which often works
# faster).
#ShowTime = IfAvailable
ShowTime = yes
# Show time played as a percentage in the time progress bar.
ShowTimePercent = yes
# Values of the TERM environment variable which are deemed to be managed by
# screen(1). If you are setting a specific terminal using screen(1)'s
# '-T <term>' option, then you will need to add 'screen.<term>' to this list.
# Note that this is only a partial test; the value of the WINDOW environment
# variable must also be a number (which screen(1) sets).
#ScreenTerms = screen:screen-w:vt100
# Values of the TERM environment variable which are deemed to be xterms. If
# you are using MOC within screen(1) under an xterm, then add screen(1)'s
# TERM setting here as well to cause MOC to update the xterm's title.
#XTerms = xterm
#XTerms += xterm-colour:xterm-color
#XTerms += xterm-256colour:xterm-256color
#XTerms += rxvt:rxvt-unicode
#XTerms += rxvt-unicode-256colour:rxvt-unicode-256color
#XTerms += eterm
# Theme file to use. This can be absolute path or relative to
# /usr/share/moc/themes/ (depends on installation prefix) or
# ~/.moc/themes/ .
#
# Example: Theme = laras_theme
#
Theme = user_moca_theme
# The theme used when running on an xterm.
#
# Example: XTermTheme = transparent-background
#
#XTermTheme =
# Should MOC try to autoload the default lyrics file for an audio? (The
# default lyrics file is a text file with the same file name as the audio
# file name with any trailing "extension" removed.)
AutoLoadLyrics = yes
# Should MOC try to autoload the lyrics for an audio from the internet?
# Specify an URL where to fetch lyrics from. %a marks the artist, %t the
# title of the song.
#LyricsUrl = "http://lyrics.wikia.com/wiki/%a:%t?action=raw"
# If the LyricsUrl above does not return raw lyrics, you can specifiy a
# regular expression to match the lyrics part within.
#LyricsRegex = "<lyrics>\n(.*)</lyrics>"
# Timeout in seconds for requesting lyrics. If you set this too high, the
# interface can become unresponive. Set to 0 to disable.
LyricsTimeout = 2
# If lyrics are fetched from the internet, should they be stored to disk?
# The lyrics are stored with the same filename as the audio file without the
# extension.
StoreLyrics = yes
# MOC directory (where pid file, socket and state files are stored).
# You can use ~ at the beginning.
#MOCDir = ~/.moc
# Use mmap() to read files. mmap() is much slower on NFS.
#UseMMap = no
# Use MIME to identify audio files. This can make for slower loading
# of playlists but is more accurate than using "extensions".
#UseMimeMagic = no
# Assume this encoding for ID3 version 1/1.1 tags (MP3 files). Unlike
# ID3v2, UTF-8 is not used here and MOC can't guess how tags are encoded.
# Another solution is using librcc (see the next option). This option is
# ignored if UseRCC is set to 'yes'.
ID3v1TagsEncoding = WINDOWS-1250
# Use librcc to fix ID3 version 1/1.1 tags encoding.
UseRCC = yes
# Use librcc to filenames and directory names encoding.
#UseRCCForFilesystem = yes
# When this option is set the player assumes that if the encoding of
# ID3v2 is set to ISO-8859-1 then the ID3v1TagsEncoding is actually
# that and applies appropriate conversion.
#EnforceTagsEncoding = no
# Enable the conversion of filenames from the local encoding to UTF-8.
FileNamesIconv = yes
# Enable the conversion of the xterm title from UTF-8 to the local encoding.
NonUTFXterm = yes
# Remember the playlist after exit?
SavePlaylist = yes  
# When using more than one client (interface) at a time, do they share
# the playlist?
SyncPlaylist = yes
# moc键盘映射配置
# Choose a keymap file (relative to '~/.moc/' or using an absolute path).
# An annotated example keymap file is included ('keymap.example').
## 一个示例文件keymap.example在 $prefix/share/moc下
#
# Example: Keymap = my_keymap
#
Keymap = keymap
# Use ASCII rather than graphic characters for drawing lines. This
# helps on some terminals.
#ASCIILines = no
# FastDirs, these allow you to jump directly to a directory, the key
# bindings are in the keymap file.
#
# Examples: Fastdir1 = /mp3/rock
# Fastdir2 = /mp3/electronic
# Fastdir3 = /mp3/rap
# Fastdir4 = /mp3/etc
# PreferredDecoders allows you to specify which decoder should be used
# for any given audio format. It is a colon-separated list in which
# each entry is of the general form 'code(decoders)', where 'code'
# identifies the audio format and 'decoders' is a comma-separated list
# of decoders in order of preference.
#
# The audio format identifier may be either a filename extension or a
# MIME media type. If the latter, the format is 'type/subtype' (e.g.,
# 'audio/flac'). Because different systems may give different MIME
# media types, any 'x-' prefix of the subtype is ignored both here and
# in the actual file MIME type (so all combinations of 'audio/flac' and
# 'audio/x-flac' match each other).
#
# For Internet streams the matching is done on MIME media type and on
# actual content. For files the matches are made on MIME media type
# (if the 'UseMimeMagic' option is set) and on filename extension. The
# MIME media type of a file is not determined until the first entry for
# MIME is encountered in the list.
#
# The matching is done in the order of appearance in the list with any
# entries added from the command line being matched before those listed
# here. Therefore, if you place all filename extension entries before
# all MIME entries you will speed up MOC's processing of directories
# (which could be significant for remote file systems).
#
# The decoder list may be empty, in which case no decoders will be used
# for files (and files with that audio format ignored) while Internet
# streams will be assessed on the actual content. Any decoder position
# may contain an asterisk, in which case any decoder not otherwise listed
# which can handle the audio format will be used. It is not an error to
# list the same decoder twice, but neither does it make sense to do so.
#
# If you have a mix of audio and non-audio files in your directories, you
# may wish to include entries at top of the list which ignore non-audio
# files by extension.
#
# In summary, the PreferredDecoders option provides fine control over the
# type of matching which is performed (filename extension, MIME media
# type and streamed media content) and which decoder(s) (if any) are used
# based on the option's list entries and their ordering.
#
# Examples: aac(aac,ffmpeg) first try FAAD2 for AACs then FFmpeg
# mp3() ignore MP3 files
# wav(*,sndfile) use sndfile for WAV as a last resort
# ogg(vorbis,*):flac(flac,*) try Xiph decoders first
# ogg():audio/ogg() ignore OGG files, and
# force Internet selection by content
# gz():html() ignore some non-audio files
#
# Any unspecified audio formats default to trying all decoders.
# Any unknown (or misspelt) drivers are ignored.
# All names are case insensitive.
# The default setting reflects the historical situation modified by
# the experience of users.
#
#PreferredDecoders = aac(aac,ffmpeg):m4a(ffmpeg)
#PreferredDecoders += mpc(musepack,*,ffmpeg):mpc8(musepack,*,ffmpeg)
#PreferredDecoders += sid(sidplay2):mus(sidplay2)
#PreferredDecoders += wav(sndfile,*,ffmpeg)
#PreferredDecoders += wv(wavpack,*,ffmpeg)
#PreferredDecoders += audio/aac(aac):audio/aacp(aac):audio/m4a(ffmpeg)
#PreferredDecoders += audio/wav(sndfile,*)
# The following PreferredDecoders attempt to handle the ambiguity surrounding
# container types such as OGG for files. The first two entries will force
# a local file to the correct decoder (assuming the .ogg file contains Vorbis
# audio), while the MIME media types will cause Internet audio streams to
# be assessed on content (which may be either Vorbis or Speex).
#
#PreferredDecoders += ogg(vorbis,ffmpeg):oga(vorbis,ffmpeg):ogv(ffmpeg)
#PreferredDecoders += opus(ffmpeg)
#PreferredDecoders += spx(speex)
#PreferredDecoders += application/ogg(vorbis):audio/ogg(vorbis)
# Which resampling method to use. There are a few methods of resampling
# sound supported by libresamplerate. The default is 'Linear') which is
# also the fastest. A better description can be found at:
#
# http://www.mega-nerd.com/libsamplerate/api_misc.html#Converters
#
# but briefly, the following methods are based on bandlimited interpolation
# and are higher quality, but also slower:
#
# SincBestQuality - really slow (I know you probably have an xx GHz
# processor, but it's still not enough to not see
# this in the top output :) The worst case
# Signal-to-Noise Ratio is 97dB.
# SincMediumQuality - much faster.
# SincFastest - the fastest bandlimited interpolation.
#
# And these are lower quality, but much faster methods:
#
# ZeroOrderHold - really poor quality, but it's really fast.
# Linear - a bit better and a bit slower.
#
#ResampleMethod = Linear
# Always use this sample rate (in Hz) when opening the audio device (and
# resample the sound if necessary). When set to 0 the device is opened
# with the file's rate.
#ForceSampleRate = 0
# By default, even if the sound card reports that it can output 24bit samples
# MOC converts 24bit PCM to 16bit. Setting this option to 'yes' allows MOC
# to use 24bit output. (The MP3 decoder, for example, uses this format.)
# This is disabled by default because there were reports that it prevents
# MP3 files from playing on some soundcards.
Allow24bitOutput = no
# Use realtime priority for output buffer thread. This will prevent gaps
# while playing even with heavy load. The user who runs MOC must have
# permissions to set such a priority. This could be dangerous, because it
# is possible that a bug in MOC will freeze your computer.
#UseRealtimePriority = no
# The number of audio files for which MOC will cache tags. When this limit
# is reached, file tags are discarded on a least recently used basis (with
# one second resolution). You can disable the cache by giving it a size of
# zero. Note that if you decrease the cache size below the number of items
# currently in the cache, the number will not decrease immediately (if at
# all).
#TagsCacheSize = 256
# Number items in the playlist.
# 显示播放列表文件编号
PlaylistNumbering = yes
# mocp播放界面布局配置
# Main window layouts can be configured. You can change the position and
# size of the menus (directory and playlist). You have three layouts and
# can switch between then using the 'l' key (standard mapping). By default,
# only two layouts are configured.
#
# The format is as follows:
#
# - Each layout is described as a list of menu entries.
# - Each menu entry is of the form:
#
# menu(position_x, position_y, width, height)
#
# where 'menu' is either 'directory' or 'playlist'.
# - The parameters define position and size of the menu. They can
# be absolute numbers (like 10) or a percentage of the screen size
# (like 45%).
# - 'width' and 'height' can have also value of 'FILL' which means
# fill the screen from the menu's position to the border.
# - Menus may overlap.
#
# You must describe at least one menu (default is to fill the whole window).
# There must be at least one layout (Layout1) defined; others can be empty.
#
# Example: Layout1 = playlist(50%,50%,50%,50%)
# Layout2 = ""
# Layout3 = ""
#
# Just one layout, the directory will occupy the whole
# screen, the playlist will have 1/4 of the screen size
# and be positioned at lower right corner. (Note that
# because the playlist will be hidden by the directory
# you will have to use the TAB key to make the playlist
# visible.)
#
# Example: Layout1 = playlist(0,0,100%,10):directory(0,10,100%,FILL)
#
# The screen is split into two parts: playlist at the top
# and the directory menu at the bottom. Playlist will
# occupy 10 lines and the directory menu the rest.
#
#Layout1 = palylist(0,0,100%,FILL)
Layout1 = playlist(0,0,FILL,100%)
#Layout2 = directory(0,0,100%,100%):playlist(0,0,100%,100%)
#Layout3 = ""
# When the song changes, should the menu be scrolled so that the currently
# played file is visible?
FollowPlayedFile = yes
# What to do if the interface was started and the server is already playing
# something from the playlist? If CanStartInPlaylist is set to 'yes', the
# interface will switch to the playlist. When set to 'no' it will start
# from the last directory.
CanStartInPlaylist = yes
# Executing external commands (1 - 10) invoked with key commands (F1 - F10
# by default).
#
# Some arguments are substituted before executing:
#
# %f - file path
# %i - title made from tags
# %S - start block mark (in seconds)
# %E - end block mark (in seconds)
#
……..
# Display full paths instead of just file names in the playlist.
# 是否显示播放列表文件全路径
PlaylistFullPaths = no
……….. 
Mocp Configure
##########################################
 
2.mocp键盘映射配置
mocp键盘映射自定义,示例键盘映射可以从$prefix/share/moc/keymap.example找到
$ vim ~/.moc/keymap
menu_up            = k UP
menu_down        = j DOWN
menu_page_up            = ^b PAGE_UP
menu_page_down        = ^d PAGE_DOWN
menu_first_item        = M-b HOME
menu_last_item        = M-d END
 
3.mocp主题
mocp主题默认安装到$prefix/share/moc/themes目录下,可以自定义主题只对用户生效(放到~/.moc/themes目录下).
mocp启动时指定的主题或者在用户级配置文件~/.moc/config中指定的主题可以自动从$prefix/share/moc/themes和~/.moc/themes中读取.(没有就要在~/.moc/config的Theme 使用绝对路径来指定)
创建~/.moc/themes目录
$ mkdir -pv ~/.moc/themes
$ cp /usr/share/moc/themes/moca_theme ~/.moc/themes/user_moca_theme 
~/.moc/themes/ user_moca_theme
mocp User themes:
##########################################
background        = white    default bold    
frame            = white    default bold    
window_title        = yellow    default    bold
directory        = white        default
selected_directory    = white        default bold
playlist        = white default
selected_playlist    = cyan        default    bold
file            = green default bold
#selected_file        = yellow    red    bold
selected_file        = white black bold
……. 
mocp User themes
##########################################
这是我的mocp最终的样子:
Linux命令行音乐播放器moc
fbterm显示出来也是这个样子的,不过桌面歌词就没有了。
注:在fbterm中将TERM变量一直设为fbterm时会让一些基于ncursers库的命令行程序界面(比如mc和alsamixer,mocp)变得乱七八糟。而只有在将TERM变量值设置为fbterm的时候才可以让vim在fbterm上支持更多的颜色。 
 
本文永久更新地址:http://www.linuxdiyf.com/linux/30601.html