2012-06-12 40 views
5

我有一個使用Microsoft.expression.encoder和框架4.0播放視頻的WPF應用程序,但我在廣播時延遲了15秒。是否有任何建議以減少播放時的延遲。下面wpf應用程序廣播延遲15秒的視頻

是我使用的MediaElement展現在我的服務器和客戶端系統的攝像頭兩個密碼

using Microsoft.Expression.Encoder.Live; 
using Microsoft.Expression.Encoder; 

private void button1_Click(object sender, RoutedEventArgs e) 
{ 
    try 
    { 
     EncoderDevice video = null; 
     EncoderDevice audio = null; 
     GetSelectedVideoAndAudioDevices(out video, out audio); 
     StopJob(); 

     if (video == null) 
     { 
      return; 
     } 

     StopJob(); 
     _job = new LiveJob(); 

     if (video != null && audio != null) 
     { 
      //StopJob(); 
      _deviceSource = null; 
      _deviceSource = _job.AddDeviceSource(video, audio); 
      _job.ActivateSource(_deviceSource); 

      // Finds and applys a smooth streaming preset   
      //_job.ApplyPreset(LivePresets.VC1HighSpeedBroadband4x3); 

      // Creates the publishing format for the job 
      PullBroadcastPublishFormat format = new PullBroadcastPublishFormat(); 
      format.BroadcastPort = 9090; 
      format.MaximumNumberOfConnections = 50; 

      // Adds the publishing format to the job 
      _job.PublishFormats.Add(format); 

      // Starts encoding 
      _job.StartEncoding(); 
     } 
     //webCamCtrl.StartCapture(); 
    } 
    catch (Exception ex) 
    { 
     WriteLogFile(this.GetType().Name, "button1_Click", ex.Message.ToString()); 
    } 

} 

在客戶端

try 
      { 

       theMainWindow.getServerIPAddress(); 
       IP = theMainWindow.machineIP; 
       MediaElement1.Source = new Uri("http://" + IP + ":9090/"); 
      } 
      catch (Exception ex) 
      { 
      } 
+0

迄今發現的解決方案呢? –

+0

KevinCloet:不,還沒.. –

回答

0

您可以通過使用PreviewWindow代替MediaElement,繞過需要在客戶端顯示它之前的流編碼消除客戶一些延遲。 PreviewWindow是一個WinForms控件,所以這隻會在WPF中起作用。

在XAML:

<WindowsFormsHost> 
    <wf:Panel x:Name="PreviewPanel" /> 
</WindowsFormsHost> 

後面的代碼:

var previewWindow = new PreviewWindow(new HandleRef(this.PreviewPanel, this.PreviewPanel.Handle)); 
_deviceSource.PreviewWindow = previewWindow; 
// .. 
_job.ActivateSource(_deviceSource);