Author Topic: Encoded WMA file not closed properly  (Read 119 times)

kafffee

  • Posts: 151
Encoded WMA file not closed properly
« on: 4 Dec '22 - 13:06 »
Hey there :-)

My code is the following:

Code: [Select]
BassWma.BASS_WMA_EncodeOpenFile(stream, Nothing, AddOn.Wma.BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, FileName)
Dim encBuffer(35000) As Byte
While Bass.BASS_ChannelIsActive(stream) = CInt(BASSActive.BASS_ACTIVE_PLAYING)
Dim Len As Integer = Bass.BASS_ChannelGetData(stream, encBuffer, 35000)
End While
BassWma.BASS_WMA_EncodeClose(stream)
Debug.WriteLine("wma encode close: " & CStr(Bass.BASS_ErrorGetCode))

The encoding works properly, but there is no way to play the encoded file or adding any metadata (via 3rd party dll)...

I get error 5 - invalid handle.

Anybody got advice?

Ian @ un4seen

  • Administrator
  • Posts: 24784
Re: Encoded WMA file not closed properly
« Reply #1 on: 5 Dec '22 - 13:47 »
You need to retain the handle returned by BASS_WMA_EncodeOpenFile and then use that in the BASS_WMA_EncodeClose call. Unlike BASS_Encode_Stop, BASS_WMA_EncodeClose doesn't accept source handles (that's why you got BASS_ERROR_HANDLE). The encoder will also be closed automatically when the source is freed, so if you don't need the stream after encoding then you could just call BASS_StreamFree.

kafffee

  • Posts: 151
Re: Encoded WMA file not closed properly
« Reply #2 on: 5 Jan '23 - 10:16 »
I am not sure what you mean. When I do this the cd tracks I am trying to rip seem to get skipped:

Code: [Select]
stream = BassWma.BASS_WMA_EncodeOpenFile(stream, Nothing, AddOn.Wma.BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, filename)
Dim encBuffer(35000) As Byte
While Bass.BASS_ChannelIsActive(stream) = CInt(BASSActive.BASS_ACTIVE_PLAYING)
           Dim Len As Integer = Bass.BASS_ChannelGetData(stream, encBuffer, 35000)
End While
BassWma.BASS_WMA_EncodeClose(stream)

Chris

  • Posts: 2104
Re: Encoded WMA file not closed properly
« Reply #3 on: 5 Jan '23 - 12:05 »
Hi, as Ian wrote
Code: [Select]
stream = BassWma.BASS_WMA_EncodeOpenFile(stream, Nothing, AddOn.Wma.BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, filename)
Dim encBuffer(35000) As Byte
While Bass.BASS_ChannelIsActive(stream) = CInt(BASSActive.BASS_ACTIVE_PLAYING)
           Dim Len As Integer = Bass.BASS_ChannelGetData(stream, encBuffer, 35000)
End While
BassWma.BASS_WMA_EncodeClose(stream)
should to be
Code: [Select]
encoder1 = BassWma.BASS_WMA_EncodeOpenFile(stream, Nothing, AddOn.Wma.BASSWMAEncode.BASS_WMA_ENCODE_SOURCE, 128000, filename)
Dim encBuffer(35000) As Byte
While Bass.BASS_ChannelIsActive(stream) = CInt(BASSActive.BASS_ACTIVE_PLAYING)
           Dim Len As Integer = Bass.BASS_ChannelGetData(stream, encBuffer, 35000)
End While
BassWma.BASS_WMA_EncodeClose(encoder1)