AlsaPlayer 介绍
1 介绍
“ALSA” 是高级Linux声音架构(Advanced Linux Sound Architecture)的缩写。
在Linux系统中,常用的音乐播放器有 Alsa Player (alsaplayer)、VLC Media Player (vlc)和MPlayer (mplayer)等。
AlsaPlayer 是一种新型 PCM 播放器。它高度多线程,并尝试大量使用 ALSA 库和驱动程序。它具有一些 Linux/Unix 播放器独有的非常有趣的功能。目标是创建一个完全可插入的框架,用于播放各种媒体,重点是 PCM 音频数据。核心代码由 Andy Lo-A-Foe 编写,许多其他人也参与其中。
AlsaPlayer 专注于两个关键领域:所有客户端的同步执行和低延迟操作。
2 AlsaPlayer vs MPlayer vs VLC Media Player
播放器 | 概述 | 特点 | 命令示例 |
---|---|---|---|
AlsaPlayer | AlsaPlayer是一个专为Linux设计的音频播放器,支持多种音频格式和声音系统。 | - 支持正负速度控制 - 支持Icecast/Shoutcast流媒体 - 界面插件 - 低延迟模式 - 多线程设计 | alsaplayer /path/to/music.mp3 |
VLC Media Player | VLC是一个自由、开源的跨平台多媒体播放器及框架,可以播放大多数多媒体文件以及流媒体协议。 | - 支持多种格式无需额外编解码器 - 跨平台运行 - 无广告、无间谍软件 | vlc /path/to/music.mp3 |
MPlayer | MPlayer是一个功能强大的电影播放器,支持广泛的文件格式和输出驱动,特别适合播放损坏的视频文件。 | - 支持多种视频和音频格式 - 强大的音频支持 - OSD功能 - MEncoder集成 | mplayer /path/to/music.mp3 |
3 命令 OPTIONS
位置
/usr/bin/alsaplayer
命令语法
alsaplayer [options] [ filename ...]
如果在命令行上指定了文件,则播放这些文件。否则 alsaplayer 播放上次运行的播放列表(如果有的话)。
基础
These programs follow the usual GNU command line syntax, with long options starting with
two dashes (`-'). A summary of options is included below.
-c, --config <file>
Use the given config file for this session.
本次会话中使用给定的配置文件。
-h, --help
Print this help message.
-i, --interface <interface>
Use the specified interface instead of the default one.
使用指定的接口,而不是默认的接口。
-I, --script <file>
Specify the script to pass to the interface plugin.
指定传递给接口插件的脚本。
-l, --startvolume <vol>
Start with this volume [default=1.0].
从此卷开始 [默认=1.0]。
-p, --path <path>
Set the path alsaplayer looks for add-ons.
设置 alsaplayer 寻找附加组件的路径。
-q, --quiet
Quiet operation, no output.
运行安静,无输出。
-s, --session-name name
Name this session "name"
将此会话命名为“name”
-v, --version
Print version of this program.
打印此程序的版本。
--verbose
Be verbose about the output.
关于输出的详细信息。
--nosave
Do not save playlist content at exit.
在退出时不要保存播放列表内容。
Player control
-n, --session #
Select session # [default=0]
选择会话 # [默认=0]
-e, --enqueue file(s)
Enqueue file(s) in a running alsaplayer.
在运行 alsaplayer 中排队文件。
-E, --replace file(s)
Clears and queues file(s) in a running alsaplayer.
在运行 alsaplayer 中清除并排队文件。
--status
Get some information about the session.
获取有关会话的一些信息。
--volume #
Set software volume [0.0-1.0].
设置软件音量 [0.0-1.0]。
--start
Start playing.
开始播放。
--stop Stop playing.
停止播放。
--pause
Pause/unpause playing.
暂停/取消暂停播放。
--prev Jump to the previous track.
跳转到上一首曲目
--next Jump to the next track.
跳转到下一首曲目
--seek <second>
Jump to the specified second in the current track.
跳转到当前曲目中的指定秒。
--relative <second>
Jump <second> seconds from current position.
从当前位置跳转 <second> 秒。
--speed <value>
Set the playback speed with -10 <= <value> <= 10. 1.0 = normal speed, -1.0 =
normal speed backwards. Be aware that alsaplayer respect your LOCALE. That implies
that the decimal point will vary accordingly. I.e., with french LOCALE, a valid
speed value is 1,5 and not 1.5.
将播放速度设置为 -10 <= <value> <= 10。1.0 = 正常速度,-1.0 = 正常速度向后。请注意,alsaplayer 尊重您的本地化。这意味着小数点将相应地变化。例如,使用法文本地化,有效的速度值为 1,5 而非 1.5。
--jump #
Jump to the specified playlist track.
跳转到指定的播放列表曲目。
--clear
Clear the whole playlist
清除整个播放列表
--quit Quit the session.
退出会话
Sound driver options
-d, --device string
Select the specific device for the output plugin. For the ALSA plugin, the default
is "default". For the JACK plugin, the default is
"alsa_pcm:playback_1,alsa_pcm:playback_2".
选择特定设备的输出插件。对于 ALSA 插件,默认值为“default”。对于 JACK 插件,默认值为“alsa_pcm:playback_1,alsa_pcm:playback_
-f, --fragsize #
Set fragment size in bytes [default=4096].
设置片段大小(字节) [默认=4096]。
-F, --frequency #
Set the output frequency [default=44100].
设置输出频率 [默认=44100]。
-g, --fragcount #
Fragment count [default=8].
片段计数 [默认=8]。
-r, --realtime
Enable realtime scheduling. To use this as a normal user, alsaplayer must be SUID
root.
启用实时调度。要作为普通用户使用,alsaplayer 必须 SUID root。
-o, --output [alsa|esound|jack|nas|null|oss|sgi|sparc]
Use the specified output driver.
使用指定的输出驱动程序。
Experimental options
-S,--loopsong
Loop the file.
循环文件。
-P,--looplist
Loop the playlist.
循环播放列表。
-x,--crossfade
Crossfade playlist entries.
交叉淡入播放列表条目。
JACK OUTPUT PLUGIN
For use with JACK, -F <sample_rate> is mandatory for best results. The value of sample rate must be the same as the one used by jackd.
对于 JACK 使用,-F <sample_rate> 是最佳结果的关键。采样率值必须与 jackd 使用的相同。
If you forget the -F parameter, the sound can be very bad. The only remedy at that time is to restart both jackd and AlsaPlayer.
如果您忘记 -F 参数,声音会很糟糕。此时唯一的方法是重新启动 jackd 和 AlsaPlayer。
DAEMON INTERFACE
With the daemon interface, it is mandatory to add the -s option. You must process in two steps to get sound with it. First launch the daemon:
使用守护程序接口,必须添加 -s 选项。使用它时,必须分两步处理才能获得声音。首先启动守护进程:
alsaplayer -i daemon -s <name>
and then add some song:
alsaplayer -e <some.song>
4 使用库开发
https://github.com/alsaplayer/alsaplayer/tree/master/libalsaplayer
- ap_string.c
- ap_string.h
- message.c
- message.h
ap_connect_session: 连接到指定的AlsaPlayer会话。
ap_message_new: 创建一个新的消息对象。
ap_message_add_key: 向消息中添加一个新的键值对。
ap_message_receive: 从一个文件描述符接收消息。
ap_message_send: 向一个文件描述符发送消息。
...
ap_play: 播放音乐。
ap_pause: 暂停音乐。
ap_stop: 停止音乐。
参考
1、官网–alsaplayer
2、github–alsaplayer
3、使用linux命令打开音乐
4、alsaplayer 命令
5、韦东山–Linux应用开发【第八章】ALSA应用开发
6、alsa-project
7、Linux音频驱动-ALSA概述
8、Qt 前奏ALSA库的移植,录音播放录音
9、RokidOS 中的音频框架