如何通过命令行启动首选音频播放器?

如何通过命令行启动首选音频播放器?

我的 bash 脚本应该直接调用用户首选音频播放器,而不是 vlc 或 mplayer。我该如何从 bash 调用它?我假设类似

audio-player --play music.mp3

答案1

尝试使用 XDG 打开,它应该使用默认应用程序打开文件:

xdg-open music.mp3

xdg-open 手册页

姓名

   xdg-open - opens a file or URL in the user's preferred application

概要

   xdg-open {file | URL}

   xdg-open {--help | --manual | --version}

描述

   xdg-open opens a file or URL in the user's preferred application. If a
   URL is provided the URL will be opened in the user's preferred web
   browser. If a file is provided the file will be opened in the preferred
   application for files of that type. xdg-open supports file, ftp, http
   and https URLs.

   xdg-open is for use inside a desktop session only. It is not
   recommended to use xdg-open as root.

相关内容