Results 1 to 4 of 4

Thread: encoder mp3 to wma problem

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    encoder mp3 to wma problem

    hello,

    i am trying to encode files (mp3 and wav) to wma format.
    I have read the encoder sdk and done a lot of googlng but for some reason the code below doesnt work.

    It creates a wma file. but of only 38 seconds in length (the source file is over 2 mins long) and the app never finishes. it just keeps going thru the loop.

    I assume i'm doing something really stupid. not even sure that
    Code:
    Me.OnStateChange(Encoder.RunState)
    is the correct thing to do. please help as im sure this is just me beign incredibly stupid.

    Code:
    Private Sub OnStateChange(ByVal enumState As WMENC_ENCODER_STATE)
    
            Select Case (enumState)
    
            Case WMENC_ENCODER_STATE.WMENC_ENCODER_RUNNING
                    ' TODO: Handle running state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
                    '// TODO: Handle stopped state.
                    bDone = True
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STARTING
                    '// TODO: Handle starting state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSING
                    '// TODO: Handle pausing state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPING
                    '// TODO: Handle stopping state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSED
                    '// TODO: Handle paused state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_END_PREPROCESS
                    '// TODO: Handle end preprocess state.
                    Exit Sub
            End Select
        End Sub
    
        Private Sub ConvertAndSaveToWma(ByVal sourceFilePath As String, ByVal destinationFilePath As String, ByVal Author As String, ByVal Copyright As String, ByVal Description As String, ByVal Rating As String, ByVal Title As String)
            ' Create a WMEncoder object.
            Dim Encoder As WMEncoder
            Encoder = New WMEncoder
    
            ' Retrieve the source group collection and add a source group. 
            Dim SrcGrpColl As IWMEncSourceGroupCollection
    
            SrcGrpColl = Encoder.SourceGroupCollection
            Dim SrcGrp As IWMEncSourceGroup2
            SrcGrp = SrcGrpColl.Add("SG_1")
    
            ' Add a video and audio source to the source group.
            Dim SrcAud As IWMEncAudioSource
            SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
    
            ' Identify the source files to encode.
            SrcAud.SetInput(sourceFilePath)
    
    
            ' Choose a profile from the collection.
            Dim ProColl As IWMEncProfileCollection
            Dim Pro As IWMEncProfile
            Dim i As Integer
            Dim lLength As Long
    
            ProColl = Encoder.ProfileCollection
            lLength = ProColl.Count
    
            For i = 0 To lLength - 1
                Pro = ProColl.Item(i)
                If Pro.Name = "Windows Media Audio 8 for Dial-up Modem (Near CD quality, 48 Kbps)" Then
                    SrcGrp.Profile = Pro
                    Exit For
                End If
            Next
    
            ' Fill in the description object members.
            Dim Descr As IWMEncDisplayInfo
            Descr = Encoder.DisplayInfo
            Descr.Author = Author
            Descr.Copyright = Copyright
            Descr.Description = Description
            Descr.Rating = Rating
            Descr.Title = Title
    
            ' Add an attribute to the collection.
            Dim Attr As IWMEncAttributes
            Attr = Encoder.Attributes
            Attr.Add("URL", "IP address")
    
            ' Specify a file object in which to save encoded content.
            Dim File As IWMEncFile
            File = Encoder.File
            File.LocalFileName = destinationFilePath
            ' Start the encoding process.
            ' Start Windows Media Encoder
            Encoder.AutoStop = True
            Encoder.RemoteAdmin = True
            'wscript.Sleep 1000
            Encoder.PrepareToEncode(True)
            Encoder.Start()
    
            Do Until (Encoder.RunState = WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED)
                Me.OnStateChange(Encoder.RunState)
            Loop
    
            MsgBox("Click OK when encoding has stopped.")
    
    
        End Sub

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: encoder mp3 to wma problem

    read another post on this sort of thign whilst searching this forum and have amde a few changes. but still doesn't work. still only creates a 39 second file.


    Code:
    'declared globally
        Private bDone As Boolean
        Dim WithEvents Encoder As WMEncoder
    
    
        Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE) Handles Encoder.OnStateChange
            Select Case (enumState)
    
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_RUNNING
                    ' TODO: Handle running state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
                    '// TODO: Handle stopped state.
                    bDone = True
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STARTING
                    '// TODO: Handle starting state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSING
                    '// TODO: Handle pausing state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPING
                    '// TODO: Handle stopping state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSED
                    '// TODO: Handle paused state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_END_PREPROCESS
                    '// TODO: Handle end preprocess state.
                    Exit Sub
            End Select
        End Sub
    
        Private Sub ConvertAndSaveToWma(ByVal sourceFilePath As String, ByVal destinationFilePath As String, ByVal Author As String, ByVal Copyright As String, ByVal Description As String, ByVal Rating As String, ByVal Title As String)
            ' Create a WMEncoder object.
    
            Encoder = New WMEncoder
    
            ' Retrieve the source group collection and add a source group. 
            Dim SrcGrpColl As IWMEncSourceGroupCollection
    
            SrcGrpColl = Encoder.SourceGroupCollection
            Dim SrcGrp As IWMEncSourceGroup2
            SrcGrp = SrcGrpColl.Add("SG_1")
    
            ' Add a video and audio source to the source group.
            Dim SrcAud As IWMEncAudioSource
            SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
    
            ' Identify the source files to encode.
            SrcAud.SetInput(sourceFilePath)
    
    
            ' Choose a profile from the collection.
            Dim ProColl As IWMEncProfileCollection
            Dim Pro As IWMEncProfile
            Dim i As Integer
            Dim lLength As Long
    
            ProColl = Encoder.ProfileCollection
            lLength = ProColl.Count
    
            For i = 0 To lLength - 1
                Pro = ProColl.Item(i)
                If Pro.Name = "Windows Media Audio 8 for Dial-up Modem (Near CD quality, 48 Kbps)" Then
                    SrcGrp.Profile = Pro
                    Exit For
                End If
            Next
    
            ' Fill in the description object members.
            Dim Descr As IWMEncDisplayInfo
            Descr = Encoder.DisplayInfo
            Descr.Author = Author
            Descr.Copyright = Copyright
            Descr.Description = Description
            Descr.Rating = Rating
            Descr.Title = Title
    
            ' Add an attribute to the collection.
            Dim Attr As IWMEncAttributes
            Attr = Encoder.Attributes
            Attr.Add("URL", "IP address")
    
            ' Specify a file object in which to save encoded content.
            Dim File As IWMEncFile
            File = Encoder.File
            File.LocalFileName = destinationFilePath
            ' Start the encoding process.
            ' Start Windows Media Encoder
            Encoder.AutoStop = True
            Encoder.RemoteAdmin = True
            'wscript.Sleep 1000
            Encoder.PrepareToEncode(True)
            Encoder.Start()
    
            while bdone = false
            end while
    
        End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: encoder mp3 to wma problem

    Ok made another change. got rid of the pointless loop. in debug the onstatchange event gets called. it even goes into the stopped case and stops the encoder. but it still only produces a file 38 seconds long (and 1290kb in size). and i don't know why.

    Any help would really be appreciated.

    Code:
        Private Sub ConvertAndSaveToWma(ByVal sourceFilePath As String, ByVal destinationFilePath As String, ByVal Author As String, ByVal Copyright As String, ByVal Description As String, ByVal Rating As String, ByVal Title As String)
            ' Create a WMEncoder object.
    
            Encoder = New WMEncoder
    
            ' Retrieve the source group collection and add a source group. 
            Dim SrcGrpColl As IWMEncSourceGroupCollection
    
            SrcGrpColl = Encoder.SourceGroupCollection
            Dim SrcGrp As IWMEncSourceGroup2
            SrcGrp = SrcGrpColl.Add("SG_1")
    
            ' Add a video and audio source to the source group.
            Dim SrcAud As IWMEncAudioSource
            SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO)
    
            ' Identify the source files to encode.
            SrcAud.SetInput(sourceFilePath)
    
    
            ' Choose a profile from the collection.
            Dim ProColl As IWMEncProfileCollection
            Dim Pro As IWMEncProfile
            Dim i As Integer
            Dim lLength As Long
    
            ProColl = Encoder.ProfileCollection
            lLength = ProColl.Count
    
            For i = 0 To lLength - 1
                Pro = ProColl.Item(i)
                If Pro.Name = "Windows Media Audio 8 for Dial-up Modem (Near CD quality, 48 Kbps)" Then
                    SrcGrp.Profile = Pro
                    Exit For
                End If
            Next
    
            ' Fill in the description object members.
            Dim Descr As IWMEncDisplayInfo
            Descr = Encoder.DisplayInfo
            Descr.Author = Author
            Descr.Copyright = Copyright
            Descr.Description = Description
            Descr.Rating = Rating
            Descr.Title = Title
    
            ' Add an attribute to the collection.
            Dim Attr As IWMEncAttributes
            Attr = Encoder.Attributes
            Attr.Add("URL", "IP address")
    
            ' Specify a file object in which to save encoded content.
            Dim File As IWMEncFile
            File = Encoder.File
            File.LocalFileName = destinationFilePath
            ' Start the encoding process.
            ' Start Windows Media Encoder
            Encoder.AutoStop = True
            Encoder.RemoteAdmin = True
            'wscript.Sleep 1000
            Encoder.PrepareToEncode(True)
            Encoder.Start()
    
        End Sub
    
        Private Sub Encoder_OnStateChange(ByVal enumState As WMEncoderLib.WMENC_ENCODER_STATE) Handles Encoder.OnStateChange
            Select Case (enumState)
    
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_RUNNING
                    ' TODO: Handle running state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPED
                    '// TODO: Handle stopped state.
                    Encoder.Stop()
                    MessageBox.Show("finished")
                    'bDone = True
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STARTING
                    '// TODO: Handle starting state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSING
                    '// TODO: Handle pausing state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_STOPPING
                    '// TODO: Handle stopping state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_PAUSED
                    '// TODO: Handle paused state.
                    Exit Sub
                Case WMENC_ENCODER_STATE.WMENC_ENCODER_END_PREPROCESS
                    '// TODO: Handle end preprocess state.
                    Exit Sub
            End Select
        End Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Norwich, UK
    Posts
    405

    Re: encoder mp3 to wma problem

    Just checked that the fiels are not the issue by using the windows encoder application to convert the test file. it worked absolutely fine. (and didn't convert only the first 38 seconds)

    still absolutely stumped on this.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width