SourceObject Property

Summary
Gets or sets the media source object.
Syntax
C#
C++/CLI
public virtual object SourceObject { get; set; } 
public: 
virtual property Object^ SourceObject { 
   Object^ get(); 
   void set (    Object^ ); 
} 

Property Value

A System.Object value representing the media source object.

Remarks

Use this property to assign a COM object as the media source for the conversion process. The object may be a SampleSource object or any other DirectShow source filter. The SourceType will be set to SourceObjectType.Object. Assignment can raise an error exception. For more information, refer to the Error Codes. Note: When setting this property, the Play control must be in the stopped state.

Example
C#
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
 
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["USB"] == null) 
         throw new Exception("No USB video devices available!"); 
 
      capturectrl.VideoDevices["USB"].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 new Exception(ex.Message); 
   } 
 
   if (!eos) 
   { 
      _playSource.DeliverSample(1000, cs); 
      _form.TestTimer.Start(); 
   } 
   else 
   { 
      _playSource.DeliverEndOfStream(1000); 
      _form.TestTimer.Stop(); 
 
      // set the result 
      _result = true; 
   } 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Multimedia Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.