ADODB.Stream crashes IE


On our website we've got a flash player that streams MP3's, the flash player is fed using an ASP script that streams the MP3 as binary data. Using Internet Explorer, and after listening to a few songs, the browser first of all becomes sluggish and then crashes. This only happens when the songs is not allowed to finish, normally when the song finishes, the flash player clears the memory of any data that has been sent to it...The player appears in a pop-up window, if the user clicks on the normal 'X' button to close the window, the flash player cannot clear the memory. I am trying to figure out whether the script i am using to stream the data will continue executing even if the calling object, i.e. the flash player, has been closed.

Within my code, can anyone see any problems in the code, or the potential for the script to continue executing even when the calling object is no longer making calls to it??

Response.Expires = 0
Response.Expiresabsolute = Now() - 1
Response.AddHeader "pragma","no-cache"
Response.AddHeader "cache-control","private"
Response.CacheControl = "no-cache"

'declare file variables
Dim strPath, strFile, strExt
Dim bolIsError, strError
Dim objMail
Dim bolIsFlashCall

'assign values to variables
strPath = Server.MapPath("/mp3/")
strFile = Request.QueryString("qryFile")
strExt = LCase(Right(strFile,Len(strFile)-inStr(strFile,".")+1))
bolIsFlashCall = Request.Form("encryption")

'//Name: GetFile()
'//Purpose: To return the file object to playlist.asp
Public Sub GetFile(strFile)

      'check a valid filename was provided
      If (strFile = "" Or strExt = "") Or (strExt <> "" And strExt = ".wma") Then
            bolIsError = True
      End If
      'only continue if a file has been provided
      If bolIsError = False Then

            'declare variables
            Dim sFile
            Dim objStream
            Dim lBlockSize
            Dim lFileSize
            Dim lCount
            'create an instance of the filesystem object
            Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
            'only continue if the file exists
            If objFso.FileExists(strPath & "\" & strFile) Then
                  'get a handle on the file
                  Set sFile = objFSO.GetFile(strPath & "\" & strFile)
                  'get the size of the file in bytes
                  lFileSize = sFile.Size
                  'create an instance of the stream object
                  Set objStream = Server.CreateObject("ADODB.Stream")
                  'open the stream
                  ' Set the Stream to Binary (not Text)
                  objStream.Type = 1
                  'load the content of the MP3/Video into the stream object
                  objStream.LoadFromFile(strPath & "\" & strFile)
                  'change the HTTP header to reflect that a binary file is being passed.
                  Response.Expires = 0
                  Response.Buffer  = True
                  'set the correct content type depending on the media type
                  Select Case strExt
                        Case ".mp3"
                              Response.ContentType = "audio/octet-stream"
                        Case ".flv"
                              Response.ContentType = "video/octet-stream"
                  End Select
                  randomize timer
                  Response.AddHeader "Content-Disposition", "inline;filename=temp" & int(rnd()*9999999999) & strExt
                  Response.AddHeader "Content-Length", lFileSize
                  Response.CharSet = "UTF-8"
                  ' While...Wend to send bulk of file
                  While lFileSize > lBlockSize + lCount And Response.IsClientConnected = True
                               lCount = lCount + lBlockSize
                               Response.BinaryWrite objStream.Read(lBlockSize)
                              ' Make sure each Block is sent before sending the next one

                  ' Main bulk of file now sent - Just the last bit to go...
                  Response.BinaryWrite objStream.Read(lFileSize - lCount)
                  ' Don't forget to flush that last little bit
                  'close all objects
                  Set objFso = Nothing
                  Set objStream = Nothing
                  Set sFile = Nothing
                  'do not execute any further
            End If 'end if file exists

End Sub

Call GetFile(strFile)

Any help would be greatly appreciated.....

Thanks in advance

Who is Participating?
deighcConnect With a Mentor Commented:
> I am trying to figure out whether the script i am using to stream the data will continue
> executing even if the calling object, i.e. the flash player, has been closed.

I understand your question then it seems to me that this isn't the problem.

The problem is with the client. If the flash app has been closed then your script may still be executing but there's no client application to receive the output - so it can't the cause the of the browser crash.

So my guess is the the flash app is NOT closing down properly or it's not sending the an HTTP disconnect header when it's closed.

At this stage I would be looking closely at the flash app before assuming it's a problem with the server-side code.

Try adding the line inside the do while loop to check whether the client is on session

if Response.IsClientConnected = false then Response.End

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.