[GS] Comment insérer un son/une musique dans une boite de dialogue ?
Bonjour
Comment insérer un son/une muisque dans une boite de dialogue ?
Solution:
Il a 2 fichiers:
- SON.html
- code.gs
SON.html
<!DOCTYPE html>
<html>
<head>
<title>Boite de dialogue son</title>
<style>
input {
display: inline-block;
float: right;
padding: 0.6rem 1rem 0.5rem;
margin-top: 1.5rem;
font-size: 1rem;
background: #e9fdf8;
border: 2px solid #4db699;
border-radius: 0.4rem;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Son</h1>
<audio controls>
<source src="https://lasonotheque.org/UPLOAD/mp3/0267.mp3" type="audio/mpeg">
</audio>
<input type="button" value="Fermer" onclick="google.script.host.close()">
</body>
</html>
La balise <audio>
permet d'insérer un son. Pour un fichier à un autre format, il faut modifier type="audio/format"
.
code.gs
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Sheets-Pratique')
.addItem('Son de la mer', 'son')
.addToUi();
}
function Son() {
const html = HtmlService.createHtmlOutputFromFile('SON')
.setWidth(400)
.setHeight(200);
SpreadsheetApp.getUi().showModalDialog(html, 'Son de la mer');
}
Il n'est pas obligé d'avoir un menu.
Bonne Journée
Fichier:
https://docs.google.com/spreadsheets/u/0/d/1OC9YmqTNduTbcJWmjJCscZ06swRwVb2wHue_Xp3oXvQ/htmlview
Bonjour,
Comment déclencher la musique a l’ouverture de la boite de dialogue ?
Utilisation d’un script est nécessaire.
<!DOCTYPE html>
<html>
<head>
<title>Boite de dialogue son</title>
<style>
input {
display: inline-block;
float: right;
padding: 0.6rem 1rem 0.5rem;
margin-top: 1.5rem;
font-size: 1rem;
background: #e9fdf8;
border: 2px solid #4db699;
border-radius: 0.4rem;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Son</h1>
<audio controls id="sonmer">
<source src="https://lasonotheque.org/UPLOAD/mp3/0267.mp3" type="audio/mpeg">
</audio>
<script>
function play(){
document.getElementById("sonmer").play;
}
play();
</script>
<input type="button" value="Fermer" onclick="google.script.host.close()">
</body>
</html>