Adds a stream-based script to be executed at a particular time during playback.
public void WriteScriptStream(string ScriptType,string ScriptCommand,double ScriptTime)
Public Sub WriteScriptStream( _ByVal ScriptType As String, _ByVal ScriptCommand As String, _ByVal ScriptTime As Double _)
public:void WriteScriptStream(String^ ScriptType,String^ ScriptCommand,double ScriptTime)
ScriptType
The name of the script command.
ScriptCommand
The script command.
ScriptTime
Time (in seconds) when the script command should execute.
Header scripts are added when you know how many scripts you have and their location beforehand. Also, since they are stored in the header, they will need to be all downloaded before playback begins. Stream scripts are added when you don't know how many you will have or when there are too many and you don't want to slow down the start of the playback. For example, if you have a live capture and there are certain notifications that you will receive during the capture, you would use stream scripts.
Stream scripts can be processed using the MediaEventHandler event handler for PlayCtrl. Stream script commands generate EC_OLE_EVENT event codes. See Processing Windows Media Script Commands for an example of how Stream Scripts are processed.
See the Microsoft documentation, Using Script Commands Supported by Windows Media Player, for a complete list of script commands supported by Windows Media Player.
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 controlstring 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 hereif (_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 capturetry{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 20\Media";}
Imports LeadtoolsImports Leadtools.MultimediaImports LeadtoolsMultimediaExamples.FixturesPublic _result As Boolean = FalsePublic _form As New CaptureCtrlForm()Public _startTime As DateTimePrivate _capturectrl As CaptureCtrlPrivate _mux As WMScriptPublic Sub WriteScriptStreamExample()_capturectrl = _form.CaptureCtrl' reference the capture controlDim 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 hereIf _capturectrl.VideoDevices("Logitech") Is Nothing ThenThrow New Exception("No USB audio device available")End If_capturectrl.VideoDevices("Logitech").Selected = TrueIf _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.WMScripterIf _mux Is Nothing ThenReturnEnd If' enable the script stream_mux.EnableScriptStream = True' subscribe to the complete eventAddHandler _capturectrl.Complete, AddressOf CaptureCtrl_Complete' subscribe to the error abort eventAddHandler _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 = 1000AddHandler _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.RunningApplication.DoEvents()End WhileEnd IfCatch generatedExceptionName As ExceptionReturnEnd 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.RunningApplication.DoEvents()End While_result = TrueEnd SubPublic Sub TestTimer_Tick(ByVal sender As Object, ByVal e As EventArgs)' stop the captureTryDim elapsedTime As Double = (DateTime.Now - _startTime).TotalMilliseconds / 1000Dim 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 TryEnd SubPublic 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 SubPublic 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 SubPublic NotInheritable Class LEAD_VARSPublic Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 20\Media"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
