audiofadeouthta

HTA. how to fade-out the embedded music mp3 (reload)


I really need some help IN All the examples I found the fade out effect was relying on the "audio id" element :

<audio id="myAudio">
    <source src="./LZ.mp3" type='audio/mp3'>
</audio>

in all cases my HTA will not play any sound It seem I can only use the "embed" or even the "bgsound" method
but then I'm lost on applying the needed fade out functions

The following code is the simplified Hta script I use to start a splash together with the mp3 music file.

<html>
<head> 
<script language="vbscript">
winWidth=350
winHeight=90
window.resizeto winWidth,winHeight
centerX=(screen.width-winWidth)/2
centerY=(screen.height-winHeight)/2
</script>
</head>
<head> 
<HTA:APPLICATION
  ID="start"
  VERSION="2.0"/>
<body>
<button style=" title="">Starting </button> <p>
</body>
</head>
 
<script type="text/javascript">
function countdown() {
var i = document.getElementById('start');
{
window.close();
}
}
setInterval(function(){ countdown(); },30000);
</script>
 <body>
 <embed audio src="./LZ.mp3"></audio >
 </body>
 </html>

The splash will last 30 secs. and on closing will cut the sounds I would like to add a fade out effect after 25 secs (5 secs. before the end)

(I cannot apply the fade out effect directly to the mp3 file because very quickly using another script I can chose to use any other mp3 )

the music will auto-start and the fade out effect should be automatic ( I mean no manual buttons)

EDIT: thanks to LesFerch my simplified hta now is playing + the music is closing with the aimed fade out effect. I'm just trying to add again the "Starting" title and the colors effects:

<body>
<button style= title="">Starting Firefox</button> <p>
   <script language="VBScript">
 Dim Intrval, direction
 Dim c   'Used to increment
Function Color(i) : Color = "#" & Hex(i) & Hex(ii) & Hex(i) : end function
Sub Window_Onload
  c = &hff
  direction = -2
  Intrval = setInterval("changeColor", 20)
end sub
sub changeColor
  document.body.bgColor = Color(c)
  c = (c + direction)
  if c > (&hff - Abs(direction)) or c < Abs(direction) then direction = -direction
end sub
</script>

Solution

  • Using the answer in the duplicate link, I made some adjustments to eliminate an IndexSizeError, play the mp3 without a button, and make the fade last a reasonable amount of time. Since your sample code starts off in VBScript, I've assumed that's your preferred language. If not, I can post a JScript version as well.

    Note: What makes this, perhaps, not a duplicate is that, for an HTA, the document mode must be declared and set to IE=9 or higher.

    Note: Document mode IE=9 and higher are much more case sensitive. For example, screen.availWidth will work, screen.AvailWidth will throw an error.

    <!DOCTYPE html>
    <html>
    <head>
    <title>Fade Test</title>
    <meta charset="UTF-8" http-equiv="X-UA-Compatible" content="IE=9">
    <hta:application
      id=oHTA
      icon=SndVol.exe
    >
    <script language="vbscript">
    Set oWSH = CreateObject("Wscript.Shell")
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    
    w = 350
    h = 90
    window.resizeTo w, h
    window.moveTo (screen.availWidth - w)/2, (screen.availHeight - h)/2
    
    MyPath  = Mid(document.URL,8)
    MyFolder = oFSO.GetParentFolderName(MyPath)
    oWSH.CurrentDirectory = MyFolder
    
    Sub window_onLoad
      mp3.play
      FadeOut
    End Sub
    
    Sub FadeOut
      If mp3.volume >= 0.1 Then
        mp3.volume = mp3.volume - 0.1
        window.setTimeout "FadeOut()", 2000
      Else
        self.close
        Exit Sub
      End If
    End Sub
    
    </script>
    <style>
    </style>
    </head>
    <body>
    <audio id="mp3">
      <source src="./LZ.mp3" type='audio/mp4'>
    </audio>
    </body>
    </html>