using System;
using WMEncoderLib;
namespace vclass.broadcast
{
	class EncodeFile
	{
		public void Main()
		{
			try 
			{
				// Create WMEncoderApp and WMEncoder objects.
				WMEncoderApp EncoderApp = new WMEncoderApp();
				IWMEncoder Encoder = EncoderApp.Encoder;

				// Display the predefined Encoder UI.
				EncoderApp.Visible = false;
				//	Şimdi bu stream ettigimiz datayı handle edelim

				// Specify the source for the input stream.
				IWMEncSourceGroupCollection SrcGrpColl = Encoder.SourceGroupCollection;
				IWMEncSourceGroup SrcGrp = SrcGrpColl.Add("SG_1");
				IWMEncSource SrcAud = SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_AUDIO);
				IWMEncVideoSource2 SrcVid = (IWMEncVideoSource2)SrcGrp.AddSource(WMENC_SOURCE_TYPE.WMENC_VIDEO);
				SrcAud.SetInput("Default_Audio_Device", "Device", "");
				SrcVid.SetInput("Default_Video_Device", "Device", "");

				// Specify a profile.
				IWMEncProfile Pro;
				IWMEncProfileCollection ProColl = Encoder.ProfileCollection;

				for (int i = 0; i < ProColl.Count; i++)
				{
					Pro = ProColl.Item(i);
					if (Pro.Name == "Windows Media Video 8 for Local Area Network (256 Kbps)")
					{
						SrcGrp.set_Profile(Pro);
						break;
					}
				}

				// Create a broadcast.
				IWMEncBroadcast BrdCst = Encoder.Broadcast;
				BrdCst.set_PortNumber (WMENC_BROADCAST_PROTOCOL.WMENC_PROTOCOL_HTTP, 10140);
				// Start the encoding process.
				Encoder.PrepareToEncode(true);
				Encoder.Start();

				// Use this statement so that the Windows Media Encoder window does not close until you press Enter.
				Console.WriteLine("Press Enter to close this window.");
				Console.ReadLine();
			} 
			catch (Exception e) 
			{  
				// TODO: Handle exceptions.
				Console.WriteLine(e.StackTrace);
			}
		}
	}
}