LEADTOOLS Multimedia (Leadtools.Multimedia assembly) Send comments on this topic. | Back to Introduction | Help Version 17.0.3.22
SetPortableType Method
See Also 
Leadtools.Multimedia Namespace > MediaType Class : SetPortableType Method



Type
A byte array containing the portable media type information to set.
Type
A byte array containing the portable media type information to set.
Specifies the media type from portable data.

Syntax

Visual Basic (Declaration) 
Public Sub SetPortableType( _
   ByVal Type() As Byte _
) 
Visual Basic (Usage)Copy Code
Dim instance As MediaType
Dim Type() As Byte
 
instance.SetPortableType(Type)
C# 
public void SetPortableType( 
   byte[] Type
)
C++/CLI 
public:
void SetPortableType( 
   array<byte>^ Type
) 

Parameters

Type
A byte array containing the portable media type information to set.

Example

Visual BasicCopy Code
Public _result As Boolean = False
Public _form As CaptureAndPlayCtrlForm = New CaptureAndPlayCtrlForm()
Public _captureTarget As SampleTarget
Public _playSource As SampleSource
Public Sub GetPortableTypeExample()
  ' reference the convert control
  Dim capturectrl As CaptureCtrl = _form.CaptureCtrl
  Dim playctrl As PlayCtrl = _form.PlayCtrl

  ' This example demonstrates how to play a capture stream 
  ' using a play control and portable media types.

  Try
     ' set the source device
     If capturectrl.VideoDevices("Analog") Is Nothing Then
       Throw New Exception("No Analog video devices available!")
     End If

     capturectrl.VideoDevices("Analog").Selected = True

     ' set the preview
     capturectrl.Preview = True

     ' create a sample target object for the capture control
     _captureTarget = New SampleTarget()

     ' set the capture target to our sample target created earlier
     capturectrl.TargetObject = _captureTarget

     ' create a new sample source object for the play control
     _playSource = New SampleSource()

     ' set the video compressor 
     capturectrl.VideoCompressors.MCmpMJpeg.Selected = True

     '// for this example we will only capture 120 seconds of video
     capturectrl.UseTimeLimit = True
     capturectrl.TimeLimit = 120

     ' start the capture
     capturectrl.StartCapture(CaptureMode.Video)

     ' we could just assign the media type from target to source
     ' however, let's use the portable type to simulate
     ' the needed steps for remote playback
     Dim portableMediaType As Byte() = _captureTarget.GetConnectedMediaType().GetPortableType()

     ' initialize a new media type object with the portable type
     Dim mt As MediaType = New MediaType()
     mt.SetPortableType(portableMediaType)

     ' set the sample source media type
     _playSource.SetMediaType(mt)

     ' set the play controls sample source object
     playctrl.SourceObject = _playSource

     ' create a timer to drive the sample delivery
     AddHandler _form.TestTimer.Tick, AddressOf SampleDeliver_Tick
     _form.TestTimer.Interval = 33
     _form.TestTimer.Start()

     ' we'll loop on the state and pump messages for this example.
     ' but you should not need to if running from a Windows Forms application.
     Do While capturectrl.State = CaptureState.Running OrElse capturectrl.State = CaptureState.Paused OrElse capturectrl.State = CaptureState.Pending
       Application.DoEvents()
     Loop
  Catch e1 As Exception
     _result = False
  End Try
End Sub

Private Sub SampleDeliver_Tick(ByVal sender As Object, ByVal e As EventArgs)
  _form.TestTimer.Stop()

  Dim eos As Boolean = False
  Dim cs As MediaSample = Nothing

  Try
     cs = _captureTarget.GetSample(1000)
  Catch cex As COMException
     If cex.ErrorCode = CInt(ErrorCode.VFW_E_SAMPLE_REJECTED_EOS) Then
       eos = True
     Else
       Throw
     End If
  Catch ex As Exception
     Throw
  End Try

  If (Not eos) Then
     _playSource.DeliverSample(1000, cs)
     _form.TestTimer.Start()
  Else
     _playSource.DeliverEndOfStream(1000)
     _form.TestTimer.Stop()

     ' set the result
     _result = True
  End If
End Sub
C#Copy Code
public bool _result = false;
public CaptureAndPlayCtrlForm _form = new CaptureAndPlayCtrlForm();
public SampleTarget _captureTarget;
public SampleSource _playSource;
public void GetPortableTypeExample()
{
   // reference the convert control
   CaptureCtrl capturectrl = _form.CaptureCtrl;
   PlayCtrl playctrl = _form.PlayCtrl;

   // This example demonstrates how to play a capture stream 
   // using a play control and portable media types.

   try
   {
      // set the source device
      if (capturectrl.VideoDevices["Analog"] == null)
         throw new Exception("No Analog video devices available!");

      capturectrl.VideoDevices["Analog"].Selected = true;

      // set the preview
      capturectrl.Preview = true;

      // create a sample target object for the capture control
      _captureTarget = new SampleTarget();

      // set the capture target to our sample target created earlier
      capturectrl.TargetObject = _captureTarget;

      // create a new sample source object for the play control
      _playSource = new SampleSource();

      // set the video compressor 
      capturectrl.VideoCompressors.MCmpMJpeg.Selected = true;

      //// for this example we will only capture 120 seconds of video
      capturectrl.UseTimeLimit = true;
      capturectrl.TimeLimit = 120;

      // start the capture
      capturectrl.StartCapture(CaptureMode.Video);

      // we could just assign the media type from target to source
      // however, let's use the portable type to simulate
      // the needed steps for remote playback
      Byte[] portableMediaType = _captureTarget.GetConnectedMediaType().GetPortableType();

      // initialize a new media type object with the portable type
      MediaType mt = new MediaType();
      mt.SetPortableType(portableMediaType);

      // set the sample source media type
      _playSource.SetMediaType(mt);

      // set the play controls sample source object
      playctrl.SourceObject = _playSource;

      // create a timer to drive the sample delivery
      _form.TestTimer.Tick += new EventHandler(SampleDeliver_Tick);
      _form.TestTimer.Interval = 33;
      _form.TestTimer.Start();

      // we'll loop on the state and pump messages for this example.
      // but you should not need to if running from a Windows Forms application.
      while (capturectrl.State == CaptureState.Running
         || capturectrl.State == CaptureState.Paused
         || capturectrl.State == CaptureState.Pending)
         Application.DoEvents();
   }
   catch (Exception)
   {
      _result = false;
   }
}

void SampleDeliver_Tick(object sender, EventArgs e)
{
   _form.TestTimer.Stop();

   bool eos = false;
   MediaSample cs = null;

   try
   {
      cs = _captureTarget.GetSample(1000);
   }
   catch (COMException cex)
   {
      if (cex.ErrorCode == (int)ErrorCode.VFW_E_SAMPLE_REJECTED_EOS)
         eos = true;
      else
         throw;
   }
   catch (Exception ex)
   {
      throw;
   }

   if (!eos)
   {
      _playSource.DeliverSample(1000, cs);
      _form.TestTimer.Start();
   }
   else
   {
      _playSource.DeliverEndOfStream(1000);
      _form.TestTimer.Stop();

      // set the result
      _result = true;
   }
}

Remarks

Specifies the media type from portable data. Only pass data obtained from GetPortableType method to this method. The portable data contains all the information to describe the media type. For example, you do not need to set MediaType.Type, etc. You can, if you want to, but you don't have to. For more information on using the high level method of acquiring the media type, refer to MediaType object. If the method fails, an error is raised. For more information, refer to the Error Codes.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 2000, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7

See Also