2014-02-26 75 views
0

我有一個列表視圖,顯示系統使用WPFMediaKit識別的所有攝像機的小預覽。用WPFMediaKit顯示現場攝像機的問題

這是我的代碼:

Window4.xaml

<Window x:Class="SampleApplication.Window4" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:WPFMediaKit="clr-namespace:WPFMediaKit.DirectShow.Controls;assembly=WPFMediaKit" 
    Title="Window4" Height="300" Width="300"> 
<Window.Resources> 
    <Style x:Key="CamerasLVStyle" TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}"> 
     <Setter Property="BorderBrush" Value="Black"/> 
     <Setter Property="BorderThickness" Value="0"/> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate> 
        <Border 
         x:Name="bd" > 
         <ScrollViewer> 
          <WrapPanel 
           ItemWidth="75" 
           ItemHeight="65" 
           IsItemsHost="True" 
           Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type ScrollContentPresenter}}}"/> 
         </ScrollViewer> 
        </Border> 
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
    <Style x:Key="CamerasLVItem" TargetType='{x:Type ListViewItem}' BasedOn='{StaticResource {x:Type ListBoxItem}}'> 
     <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
     <Setter Property="VerticalContentAlignment" Value="Stretch"/> 
     <Setter Property="Margin" Value="0,0,0,0"/> 
     <Setter Property="ContentTemplate"> 
      <Setter.Value> 
       <DataTemplate> 
        <Border 
         Background="#FF1E2225"> 
         <WPFMediaKit:VideoCaptureElement x:Name="videoCapElement" 
                 LoadedBehavior="Play" 
                 VideoCaptureDevice="{Binding}"/> 
        </Border> 
       </DataTemplate> 
      </Setter.Value> 
     </Setter> 
     <Setter Property="ToolTip"> 
      <Setter.Value> 
       <StackPanel> 
        <TextBlock Text="{Binding Name}"/> 
       </StackPanel> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</Window.Resources> 
<Grid> 
    <ListView x:Name="CamerasList" 
      Grid.Column="1" 
      Background="{x:Null}" 
      SelectionMode="Single" 
      ItemsSource="{Binding Cameras}" 
      Style="{StaticResource CamerasLVStyle}" 
      ItemContainerStyle="{StaticResource CamerasLVItem}"/> 
</Grid> 

Window4.xam.cs

public partial class Window4 : Window 
{ 
    private List<DsDevice> _cameras; 
    public List<DsDevice> Cameras 
    { 
     get { return _cameras; } 
     set { _cameras = value; } 
    } 

    public Window4() 
    { 
     InitializeComponent(); 

     Cameras = MultimediaUtil.VideoInputDevices.ToList(); 
     this.DataContext = this; 
    } 
} 

在一些電腦正常工作,並顯示所有的攝像機,但在其他一些沒有。

例如,我有一個帶集成攝像頭和Microsoft LifeCam影院的Windows 8.1筆記本電腦。

有時會顯示第一個,有時顯示第二個,但不會同時顯示(均顯示黑色方塊,但只顯示一個流)。

有什麼建議嗎? 謝謝。

回答

0

有些時候它顯示的第一個,有時它顯示了第二,但從來都在同一時間

典型2+ USB攝像頭不能一起工作的原因(仍然可能單獨運行良好)是USB帶寬不足以讓它們同時運行。有一個帶寬限制,這是相當低的:一個同步管道(通常用於視頻)的最大吞吐量是24MB/s。

如果兩臺攝像機連接到兩個不同的根集線器,它就可以工作。

更多關於這個問題:

0

嗯,我發現了這個問題。

經過大量的嘗試,與代碼爭鬥,問題是硬件。

如果我將Microsoft LifeCam Cinema連接到筆記本電腦的USB端口,而不是將其連接到USB連接到筆記本計算機的輔助顯示器的USB端口,則兩個相機會同時顯示在應用程序中。

我不知道爲什麼,但是......

相關問題