The following program illustrates how to build a small Windows Application to perform the following actions:

    1. Select a Video and Audio Device Source (see Figure 2)
    2. Open the associated Device Source Configuration Dialog (see Figure 3)
    3. Start an Encode Session (see Figure 4)
    4. End the Encode Session (see Figure 5)

Keep in mind that this is only a sample application and provided to demonstrate the process to perform the steps mentioned above demonstrates the items listed above. Thanks again to my colleagues Rob Dil and Carmine Sirignano for their assistance and collaboration on this sample.

This programming sample is provided As-is for illustration only, without warranty either expressed or implied. The sample assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.

INSTRUCTIONS:
Review the figures below along with the code sample them simply Copy and Paste the following code into your Microsoft Visual Studio 2010 VB.net project, build the project, add the necessary Expression Encoder references, controls, and change the encoding path to one you have available.

Sample below: ScreenCap.zip


Figure 1

  

Figure 2

 

Figure 3

  Figure 4

  Figure 5

 

  Application Code

Imports Microsoft.Expression.Encoder
Imports Microsoft.Expression.Encoder.Live
Imports Microsoft.Expression.Encoder.Devices
Imports System.Runtime.InteropServices
Imports System.Windows

Public Class Form1

    Private deviceSource As LiveDeviceSource
    Private job As New LiveJob

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
    End Sub

   'Button1 = "Configure Video"
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button2.Enabled = False
        Button1.Enabled = True
        Button3.Enabled = True
        Button4.Enabled = False

        If deviceSource IsNot Nothing Then
            deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoCaptureDialog, (New HandleRef(Panel1, Panel1.Handle)))
        End If
    End Sub

    Private Function Panel() As Object
        Throw New NotImplementedException
    End Function

    'Button2 = "Set Device Source"
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        domything()
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False
    End Sub

    Private Sub domything()
        Dim video As EncoderDevice = If(EncoderDevices.FindDevices(EncoderDeviceType.Video).Count > 0, EncoderDevices.FindDevices(EncoderDeviceType.Video)(0), Nothing)

        Dim audio As EncoderDevice = If(EncoderDevices.FindDevices(EncoderDeviceType.Audio).Count > 0, EncoderDevices.FindDevices(EncoderDeviceType.Audio)(0), Nothing)

        Dim fileOut As New FileArchivePublishFormat()
        Dim stream As New PullBroadcastPublishFormat()

        ' Gets timestamp and edits it for filename

        Dim timeStamp As String = DateTime.Now.ToString()
        timeStamp = timeStamp.Replace("/", "-")
        timeStamp = timeStamp.Replace(":", ".")

        ' Sets file path and name
        ' Note: output folder must be already created in C:

        fileOut.OutputFileName = "C:\Capture " & timeStamp & ".wmv"
        stream.BroadcastPort = 8089

        ' Adds the format to the job. You can add additional formats as well such as
        ' Publishing streams or broadcasting from a port

        job.PublishFormats.Add(fileOut)
        job.PublishFormats.Add(stream)

       ' Create a new device source. We use the first audio and video devices on the system
        deviceSource = job.AddDeviceSource(video, audio)

        ' sets preview window to winform panel hosted by xaml window
        deviceSource.PreviewWindow = New PreviewWindow(New HandleRef(Panel1, Panel1.Handle))

        ' Make this source the active one
        job.ActivateSource(deviceSource)

    End Sub

    Private Function LiveDeviceSource() As LiveDeviceSource
        Throw New NotImplementedException
    End Function

    'Button3 = "Start Encoding"
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = True

        'Start(encoding)
        job.StartEncoding()

    End Sub

    'Button4 "Stop Encoding"
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Button1.Enabled = False
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = True

        'Stop(encoding)
        job.StopEncoding()

        'Reset Buttons to default values
        Button1.Enabled = True
        Button2.Enabled = False
        Button3.Enabled = False
        Button4.Enabled = False

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Close()
    End Sub

End Class