使用 Chrome 扩展将 YouTube 播放器控件添加到 Linux 桌面
视频播放
一个我怀念的 Unity 功能（虽然只使用了一小段时间）是在 Web 浏览器中访问 YouTube 等网站时在 Ubuntu 声音指示器中自动出现播放器控件，因此你可以直接从顶部栏暂停或停止视频，以及浏览视频/歌曲信息和预览。


这个 Unity 功能已经消失很久了，但我正在为 Gnome Shell 寻找类似的东西，然后我遇到了 [browser-mpris2](https://github.com/otommod/browser-mpris2)，这是一个为 Google Chrome/Chromium 实现 MPRIS v2 接口的扩展，目前只支持 YouTube，我想可能会有一些读者会喜欢这个。


该扩展还适用于 Opera 和 Vivaldi 等基于 Chromium 的 Web 浏览器。


browser-mpris2 也支持 Firefox，但因为通过 `about:debugging` 加载扩展是临时的，而这是 browser-mpris2 所需要的，因此本文不包括 Firefox 的指导。开发人员[打算](https://github.com/otommod/browser-mpris2/issues/11)将来将扩展提交到 Firefox 插件网站上。


使用此 Chrome 扩展，你可以在支持 MPRIS2 的 applets 中获得 YouTube 媒体播放器控件（播放、暂停、停止和查找  
 ）。例如，如果你使用 Gnome Shell，你可将 YouTube 媒体播放器控件作为永久显示的控件，或者你可以使用 Media Player Indicator 之类的扩展来实现此目的。在 Cinnamon /Linux Mint with Cinnamon 中，它出现在声音 Applet 中。


我无法在 Unity 上用它，我不知道为什么。我没有在不同桌面环境（KDE、Xfce、MATE 等）中使用其他支持 MPRIS2 的 applet 尝试此扩展。如果你尝试过，请告诉我们它是否适用于你的桌面环境/支持 MPRIS2 的 applet。


以下是在使用 Gnome Shell 的 Ubuntu 18.04 并装有 Chromium 浏览器的[媒体播放器指示器](https://extensions.gnome.org/extension/55/media-player-indicator/)的截图，其中显示了有关当前正在播放的 YouTube 视频的信息及其控件（播放/暂停，停止和查找）：


[![](/data/attachment/album/201810/12/224247k2255srr5kzwcmuq.png)](https://extensions.gnome.org/extension/55/media-player-indicator/)


在 Linux Mint 19 Cinnamon 中使用其默认声音 applet 和 Chromium 浏览器的截图：


![](/data/attachment/album/201810/12/224302u2xj7q8qohrk01oo.png)


### 如何为 Google Chrom/Chromium安装 browser-mpris2


1、 如果你还没有安装 Git 就安装它


在 Debian/Ubuntu/Linux Mint 中，使用此命令安装 git：



```
sudo apt install git
```

2、 下载并安装 [browser-mpris2](https://github.com/otommod/browser-mpris2) 所需文件。


下面的命令克隆了 browser-mpris2 的 Git 仓库并将 chrome-mpris2 安装到 `/usr/local/bin/`（在一个你可以保存 browser-mpris2 文件夹的地方运行 `git clone ...` 命令，由于它会被 Chrome/Chromium 使用，你不能删除它）：



```
git clone https://github.com/otommod/browser-mpris2
sudo install browser-mpris2/native/chrome-mpris2 /usr/local/bin/
```

3、 在基于 Chrome/Chromium 的 Web 浏览器中加载此扩展。


![](/data/attachment/album/201810/12/224312dcarrqqqymg3nwat.png)


打开 Goog​​le Chrome、Chromium、Opera 或 Vivaldi 浏览器，进入 Extensions 页面（在 URL 栏中输入 `chrome://extensions`），在屏幕右上角切换到“开发者模式”。然后选择 “Load Unpacked” 并选择 chrome-mpris2 目录（确保没有选择子文件夹）。


复制扩展 ID 并保存它，因为你以后需要它（它类似于这样：`emngjajgcmeiligomkgpngljimglhhii`，但它会与你的不一样，因此确保使用你计算机中的 ID！）。


4、 运行 `install-chrome.py`（在 `browser-mpris2/native` 文件夹中），指定扩展 id 和 chrome-mpris2 路径。


在终端中使用此命令（将 `REPLACE-THIS-WITH-EXTENSION-ID` 替换为上一步中 `chrome://extensions` 下显示的 browser-mpris2 扩展 ID）安装此扩展：



```
browser-mpris2/native/install-chrome.py REPLACE-THIS-WITH-EXTENSION-ID /usr/local/bin/chrome-mpris2
```

你只需要运行此命令一次，无需将其添加到启动或其他类似的地方。你在 Google Chrome 或 Chromium 浏览器中播放的任何 YouTube 视频都应显示在你正在使用的任何 MPRISv2 applet 中。你无需重启 Web 浏览器。




---


via: <https://www.linuxuprising.com/2018/08/add-youtube-player-controls-to-your.html>


作者：[Logix](https://plus.google.com/118280394805678839070) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


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


OK
# Add YouTube Player Controls To Your Linux Desktop With browser-mpris2 (Chrome Extension)

A Unity feature that I miss (it only actually worked for a short while though) is automatically getting player controls in the Ubuntu Sound Indicator when visiting a website like YouTube in a web browser, so you could pause or stop the video directly from the top bar, as well as see the video / song information and a preview.


This Unity feature is long dead, but I was searching for something similar for Gnome Shell and I came across









Here is a screenshot with



And in Linux Mint 19 Cinnamon with its default sound applet and Chromium browser:








In Debian / Ubuntu / Linux Mint, use this command to install git:





The commands below clone the browser-mpris2 Git repository and install the chrome-mpris2 file to






Open Google Chrome, Chromium, Opera or Vivaldi web browsers, go to the Extensions page (enter


Copy the extension ID and save it because you'll need it later (it's something like:




Use this command in a terminal (replace



You only need to run this command once, there's no need to add it to startup or anything like that. Any YouTube video you play in Google Chrome or Chromium browsers should show up in whatever MPRISv2 applet you're using. There's no need to restart the web browser.



This Unity feature is long dead, but I was searching for something similar for Gnome Shell and I came across

**, and I thought there might be some Linux Uprising readers who'll like this.**[browser-mpris2](https://github.com/otommod/browser-mpris2), an extension that implements a MPRIS v2 interface for Google Chrome / Chromium, which currently only supports YouTube**The extension also works with Chromium-based web browsers like Opera and Vivaldi.**

**browser-mpris2 also supports Firefox but since loading extensions via about:debugging is temporary, and this is needed for browser-mpris2, this article doesn't include Firefox instructions. The developer**[intends](https://github.com/otommod/browser-mpris2/issues/11)to submit the extension to the Firefox addons website in the future.**Using this Chrome extension you get YouTube media player controls (play, pause, stop and seeking) in MPRIS2-capable applets**. For example, if you use Gnome Shell, you get YouTube media player controls as a permanent notification or, you can use an extension like Media Player Indicator for this. In Cinnamon / Linux Mint with Cinnamon, it shows up in the Sound Applet.**It didn't work for me on Unity**, I'm not sure why. I didn't try this extension with other MPRIS2-capable applets available in various desktop environments (KDE, Xfce, MATE, etc.). If you give it a try, let us know if it works with your desktop environment / MPRIS2 enabled applet.Here is a screenshot with

[Media Player Indicator](https://extensions.gnome.org/extension/55/media-player-indicator/)displaying information about the currently playing YouTube video, along with its controls (play/pause, stop and seeking), on Ubuntu 18.04 with Gnome Shell and Chromium browser:And in Linux Mint 19 Cinnamon with its default sound applet and Chromium browser:

**Related:**[Fix Media Player Indicator Extension Misaligned Controls / Text On Gnome Shell 3.28](https://www.linuxuprising.com/2018/05/fix-media-player-indicator-extension.html)## How to install browser-mpris2 for Google Chrome / Chromium

**1. Install Git if you haven't already.**In Debian / Ubuntu / Linux Mint, use this command to install git:

`sudo apt install git`


**2. Download and install the**[browser-mpris2](https://github.com/otommod/browser-mpris2)required files.The commands below clone the browser-mpris2 Git repository and install the chrome-mpris2 file to

`/usr/local/bin/`

(run the "git clone..." command in a folder where you can continue to keep the browser-mpris2 folder because you can't remove it, as it will be used by Chrome / Chromium):```
git clone https://github.com/otommod/browser-mpris2
sudo install browser-mpris2/native/chrome-mpris2 /usr/local/bin/
```


**3. Load the extension in Chrome / Chromium-based web browsers.**Open Google Chrome, Chromium, Opera or Vivaldi web browsers, go to the Extensions page (enter

`chrome://extensions`

in the URL bar), enable `Developer mode`

using the toggle available in the top right-hand side of the screen, then select `Load Unpacked`

and select the chrome-mpris2 directory (make sure to not select a subfolder).Copy the extension ID and save it because you'll need it later (it's something like:

`emngjajgcmeiligomkgpngljimglhhii`

but it's different for you so make sure to use the ID from your computer!) .**4. Run**`install-chrome.py`

(from the `browser-mpris2/native`

folder), specifying the extension id and chrome-mpris2 path.Use this command in a terminal (replace

`REPLACE-THIS-WITH-EXTENSION-ID`

with the browser-mpris2 extension ID displayed under `chrome://extensions`

from the previous step) to install this extension:`browser-mpris2/native/install-chrome.py REPLACE-THIS-WITH-EXTENSION-ID /usr/local/bin/chrome-mpris2`


You only need to run this command once, there's no need to add it to startup or anything like that. Any YouTube video you play in Google Chrome or Chromium browsers should show up in whatever MPRISv2 applet you're using. There's no need to restart the web browser.

**Chrome-related:**