-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
var audio; | ||
|
||
// Listen for messages from the extension | ||
chrome.runtime.onMessage.addListener((msg) => { | ||
if ("play" in msg) playAudio(msg.play); | ||
if ("stop" in msg) stopAudio(); | ||
}); | ||
|
||
// Play sound with access to DOM APIs | ||
function playAudio({ source, volume }) { | ||
const audio = new Audio(source); | ||
async function playAudio({ source, volume }) { | ||
audio = new Audio(source); | ||
audio.volume = volume; | ||
// audio.playbackRate=0.5; | ||
audio.play(); | ||
// audio.onended = onended | ||
} | ||
|
||
// async function playSound(source = 'default.wav', volume = 1) { | ||
// await createOffscreen(); | ||
// await chrome.runtime.sendMessage({ play: { source, volume } }); | ||
// } | ||
|
||
// createOffscreen(); | ||
// Create the offscreen document if it doesn't already exist | ||
// async function createOffscreen() { | ||
// if (await chrome.offscreen.hasDocument()) return; | ||
// await chrome.offscreen.createDocument({ | ||
// url: "offscreen.html", | ||
// reasons: ["AUDIO_PLAYBACK"], | ||
// justification: "testing", // details for using the API | ||
// }); | ||
// } | ||
function stopAudio() { | ||
if (!audio) { | ||
return; | ||
} | ||
audio.pause(); | ||
audio.currentTime = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters