FPHTMLBGsound Object


Represents the BGSOUND element in an HTML document. The BGSOUND element plays a sound file in the background when a document is loaded into a browser. Use the FPHTMLBGsound object to specify the location of an audio file and looping characteristics of the background sound. See also the IHTMLBGsound object.
Using the FPHTMLBGsound object
Use the Item method to return an FPHTMLBGsound object. The following example inserts the BGSOUND element into the specified document and sets the src and loop attributes according to the values passed into the function.
Function InsertBGSound(objdoc As FPHTMLDocument, strSRC As String, _
Optional intLoops As Integer) As Boolean
Dim objBGSound As FPHTMLBGsound
Dim intNumber As Integer
Dim objHead As IHTMLElement
On Error GoTo InsertBGSoundError
intNumber = objdoc.body.all.Length
Set objHead = objdoc.all.tags("head").Item(0)
objHead.insertAdjacentHTML "beforeend", _
"<BGSOUND id=""bgsound" & intNumber & """>"
Set objBGSound = objdoc.all.tags("bgsound") _
.Item(CVar("bgsound" & intNumber))
With objBGSound
.src = strSRC
If intLoops <> 0 Then
.loop = intLoops
Else
.loop = "infinite"
End If
End With
InsertBGSound = True
ExitFunction:
Exit Function
InsertBGSoundError:
InsertBGSound = False
GoTo ExitFunction
End Function
Use the following example to call the preceding function. This example assumes that you have a sound file called "song.avi" in your Web site in a subfolder called "Sounds." To see the BGSOUND element as it would function in a browser, replace the String "../sounds/song.avi" with the path and filename of a valid sound file in your Web site.
Sub CallInsertBGSound()
MsgBox InsertBGSound(ActiveDocument, "../sounds/song.avi", 5)
End Sub