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
is the correct thing to do. please help as im sure this is just me beign incredibly stupid.Code:Me.OnStateChange(Encoder.RunState)
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




Reply With Quote