LEADTOOLS Multimedia (Leadtools.Multimedia assembly)

WMScripter Property (CaptureCtrl)

Show in webframe
Example 



Provides a way to get the WMScript object.
Syntax
'Declaration
 
Public ReadOnly Property WMScripter As WMScript
'Usage
 
Dim instance As CaptureCtrl
Dim value As WMScript
 
value = instance.WMScripter
public WMScript WMScripter {get;}
public:
property WMScript^ WMScripter {
   WMScript^ get();
}

Property Value

A WMScript object, which can be used to manage the Windows Media Script commands.
Remarks
The object is read-only and can be null if the TargetFormat property is not set to TargetFormatType.WMVMux or TargetFormatType.ASFMux. You can keep a copy of the object but only as long as the target format doesn't change. If the target format changes, you should get the object again.

For more information on Windows Media Script Commands, refer to WMScript object.

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Multimedia
Imports LeadtoolsMultimediaExamples.Fixtures

Public _result As Boolean = False
Public _form As New CaptureCtrlForm()
Public _startTime As DateTime
Private _capturectrl As CaptureCtrl
Private _mux As WMScript
Public Sub WriteScriptStreamExample()
   _capturectrl = _form.CaptureCtrl

   ' reference the capture control
   Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "WriteScriptStream_Dest.wmv")

   Try
      _capturectrl.TargetFormat = TargetFormatType.WMVMux
      _capturectrl.TargetFile = outFile

      ' set an audio device, use the name of your device here
      If _capturectrl.VideoDevices("Logitech") Is Nothing Then
         Throw New Exception("No USB audio device available")
      End If

      _capturectrl.VideoDevices("Logitech").Selected = True

      If _capturectrl.IsModeAvailable(CaptureMode.Video) Then

         _capturectrl.FrameDelay = 0.033 ' 30 frames per second

         _capturectrl.TimeLimit = 10 ' just 10 seconds of capture time
         _capturectrl.UseTimeLimit = True

         ' call ReadyCapture, so the target object is added
         _capturectrl.ReadyCapture(CaptureMode.Video Or CaptureMode.InhibitRun)

         ' get the scripter object
         _mux = _capturectrl.WMScripter
         If _mux Is Nothing Then
            Return
         End If

         ' enable the script stream
         _mux.EnableScriptStream = True

         ' subscribe to the complete event
         AddHandler _capturectrl.Complete, AddressOf CaptureCtrl_Complete

         ' subscribe to the error abort event
         AddHandler _capturectrl.ErrorAbort, AddressOf CaptureCtrl_ErrorAbort

         ' set the start time
         _startTime = DateTime.Now

         ' set a timer so we can write the Script commands every second
         _form.TestTimer.Interval = 1000
         AddHandler _form.TestTimer.Tick, AddressOf TestTimer_Tick
         _form.TestTimer.Start()

         ' start the capture process
         _capturectrl.StartCapture(CaptureMode.Video)

         ' 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
            Application.DoEvents()
         End While
      End If
   Catch generatedExceptionName As Exception
      Return
   End Try

   ' 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
      Application.DoEvents()
   End While

   _result = True
End Sub

Public Sub TestTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)
   ' stop the capture
   Try
      Dim elapsedTime As Double = (DateTime.Now - _startTime).TotalMilliseconds / 1000
      Dim sz As [String] = [String].Format("Sample caption script at {0} seconds", elapsedTime)
      _mux.WriteScriptStream("caption", sz, elapsedTime)
   Catch generatedExceptionName As Exception
      _result = False
      _capturectrl.StopCapture()
   End Try
End Sub

Public Sub CaptureCtrl_Complete(ByVal sender As Object, ByVal e As EventArgs)
   ' set result
   _result = True
   ' the capture has finished, don't write scripts anymore
   ' Note that since the capture has finished automatically, I don't need to call _mux.CloseScriptStream()
   _form.TestTimer.[Stop]()
End Sub

Public Sub CaptureCtrl_ErrorAbort(ByVal sender As Object, ByVal e As ErrorAbortEventArgs)
   ' set result
   _result = False
   ' the capture has finished, don't write scripts anymore
   ' Note that since the capture has finished automatically, I don't need to call _mux.CloseScriptStream()
   _form.TestTimer.[Stop]()
End Sub

Public NotInheritable Class LEAD_VARS
Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 18\Media"
End Class
using Leadtools;
using Leadtools.Multimedia;
using LeadtoolsMultimediaExamples.Fixtures;

public bool _result = false;
public CaptureCtrlForm _form = new CaptureCtrlForm();
public DateTime _startTime;
CaptureCtrl _capturectrl;
WMScript _mux;
public void WriteScriptStreamExample()
{
   _capturectrl = _form.CaptureCtrl;

   // reference the capture control
   string outFile = Path.Combine(LEAD_VARS.MediaDir,"WriteScriptStream_Dest.wmv");

   try
   {
      _capturectrl.TargetFormat = TargetFormatType.WMVMux;
      _capturectrl.TargetFile = outFile;

      // set an audio device, use the name of your device here
      if(_capturectrl.VideoDevices["Logitech"] == null)
         throw new Exception("No USB audio device available");

      _capturectrl.VideoDevices["Logitech"].Selected = true;

      if (_capturectrl.IsModeAvailable(CaptureMode.Video))
      {
         _capturectrl.FrameDelay = .033;  // 30 frames per second
         _capturectrl.TimeLimit = 10;     // just 10 seconds of capture time
         _capturectrl.UseTimeLimit = true;

         // call ReadyCapture, so the target object is added
         _capturectrl.ReadyCapture(CaptureMode.Video | CaptureMode.InhibitRun);

         // get the scripter object
         _mux = _capturectrl.WMScripter;
         if(_mux == null)
            return;

         // enable the script stream
         _mux.EnableScriptStream = true;

         // subscribe to the complete event
         _capturectrl.Complete += new EventHandler(CaptureCtrl_Complete);

         // subscribe to the error abort event
         _capturectrl.ErrorAbort += new ErrorAbortEventHandler(CaptureCtrl_ErrorAbort);

         // set the start time
         _startTime = DateTime.Now;

         // set a timer so we can write the Script commands every second
         _form.TestTimer.Interval = 1000;
         _form.TestTimer.Tick += new EventHandler(TestTimer_Tick);
         _form.TestTimer.Start();

         // start the capture process
         _capturectrl.StartCapture(CaptureMode.Video);

         // 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)
            Application.DoEvents();
      }
   }
   catch (Exception)
   {
      return;
   }

   // 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)
      Application.DoEvents();

   _result = true;
}

public void TestTimer_Tick(object sender, EventArgs e)
{
   // stop the capture
   try
   {
      double elapsedTime = (DateTime.Now - _startTime).TotalMilliseconds / 1000;
      String sz = String.Format("Sample caption script at {0} seconds", elapsedTime);
      _mux.WriteScriptStream("caption", sz, elapsedTime);
   }
   catch(Exception)
   {
      _result = false;
      _capturectrl.StopCapture();
   }
}

public void CaptureCtrl_Complete(object sender, EventArgs e)
{
   // set result
   _result = true;
   // the capture has finished, do not write scripts anymore
   // Note that since the capture has finished automatically, I do not need to call _mux.CloseScriptStream()
   _form.TestTimer.Stop();
}

public void CaptureCtrl_ErrorAbort(object sender, ErrorAbortEventArgs e)
{
   // set result
   _result = false;
   // the capture has finished, do not write scripts anymore
   // Note that since the capture has finished automatically, I do not need to call _mux.CloseScriptStream()
   _form.TestTimer.Stop();
}

static class LEAD_VARS
{
public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 18\Media";
}
Requirements

Target Platforms

See Also

Reference

CaptureCtrl Class
CaptureCtrl Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.

Leadtools.Multimedia requires a Multimedia or Multimedia Suite license and unlock key. For more information, refer to: LEADTOOLS Toolkit Features