My blog tells about WMS9, can implement streaming media server, but without WME (Windows Media Encoder) support, always feel the lack of something, Here's how to get the device video audio stream through the. NET implementation WME and push it to remote (of course, local) streaming media broadcast publishing point.
First, download the WME9 SDK, installation completed: This step is to experience the main WME can achieve those functions.
The reader can try it on its own installation.
Two. Create. NET WinForm application, add reference using Wmencoderlib;
Wmencoderlib is a assemble, through which we can facilitate the implementation of WME operations.
Three. Get the local screen and convert it to the video signal iwmencsource Srcaud = Srcgrp.addsource (wmenc_source_type. Wmenc_audio);
Iwmencsource Srcvid = Srcgrp.addsource (wmenc_source_type. Wmenc_video);
Srcaud.setinput ("Default_audio_device", "Device", "");
Srcvid.setinput ("ScreenCapture1", "Screencap", "");
Four. Start encoder, push to remote WMS Server/Set up the push broadcast.
Iwmencpushdistribution pushdist = (iwmencpushdistribution) encoder.broadcast;
String strservername = this. TB_ServerName.Text.Trim () + ":" + this. TB_Port.Text.Trim ();
String strpubpoint = "Tmpbroadcastpubpoint";
Remove the publishing point when the broadcast was over.
Pushdist.autoremovepublishingpoint = true;
Set the push distribution variables.
Pushdist.servername = strServerName;
Pushdist.publishingpoint = Strpubpoint;
Pushdist.template = strpubtemplate;
Initialize the encoding process.
Encoder.preparetoencode (TRUE);
Note: Here, push directly to the remote server, if the server is not in the same domain, or in the untrusted zone, the push should need to verify the user name and password. So we need to create a delegate: Encoder.onacquirecredentials + = new _iwmencoderevents_onacquirecredentialseventhandler (OnUserAuth);
public void Onuserauth (string bstrrealm, String bstrsite, ref object Pvaruser, ref object Pvarpassword, re F Object Plflags)
... {
Pvaruser = "Administrator";
Pvarpassword = "622316";
Plflags = 4;
}
Five. It's almost over here, the complete code is posted: using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;
Using Wmencoderlib;
Namespace Project2
... {
public partial class Form1:form
... {
static bool Bdone;
Private Wmencoder encoder;
Public Form1 ()
... {
InitializeComponent ();
Encoder = new Wmencoder ();
Encoder.onstatechange + = new _iwmencoderevents_onstatechangeeventhandler (onwmestatuschange);
Encoder.onerror + = new _iwmencoderevents_onerroreventhandler (encoder_onerror);
Encoder.onacquirecredentials + = new _iwmencoderevents_onacquirecredentialseventhandler (OnUserAuth);
}
private void Btn_start_click (object sender, EventArgs e)
... {
This. Startbroadcast ();
}
private void Btn_close_click (object sender, EventArgs e)
... {
This. Stopbroadcast ();