单击鼠标添加声音

问题描述 投票:0回答:1

我正在为我的主题创建一个辅助GNOME扩展。当单击按钮时,该辅助扩展程序旨在用于添加一些声音,但是,找不到用于显示如何添加声音以及如何调用它们的解决方案(和扩展程序)。

实际上,我发现了一些问题和文章,它们解释了如何添加音频功能,但大多数都需要HTML。

我尝试使用here中的代码(通过Looking Glass和extension.js文件),它表示不需要HTML内容:

function playSound() {
    var audio = new Audio('/path/to/audio/file');
    audio.play();
}

但是,它返回了Audio()的未知函数错误:

ReferenceError: Audio is not defined

有人可以帮我吗?谢谢!

javascript audio gnome gnome-shell-extensions
1个回答
0
投票

如果使用的是GNOME Shell> = 3.32,则可以使用MetaSoundPlayer:

let player = global.display.get_sound_player();

// Themed sound
player.play_from_theme('phone-incoming-call', 'arbitrary description', null);

// File name
player.play_from_file('/some/path/sound.ogg', 'arbitrary description', null);

或者GNOME Shell中有全局函数<= 3.30(old docs):

// Themed sound
global.play_theme_sound(0, 'phone-incoming-call', 'arbitrary description', null);


// File name
global.play_sound_file(0, '/some/path/sound.ogg', 'arbitrary description', null);

gnome-shell提交显示了两个here的示例。

© www.soinside.com 2019 - 2024. All rights reserved.