2017-02-18 71 views
1

我將這個庫添加到我的UWP項目,並試圖運行一個簡單的媒體文件,並得到錯誤ffmpeginterop.ffmpeginteropmss未註冊,以下是我的代碼。ffmpeginterop.uwp庫給錯誤的未註冊

  try 
      { 
       // Instantiate FFmpegInteropMSS using the opened local file stream 
       FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, false, false); 
       MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); 

       if (mss != null) 
       { 
        // Pass MediaStreamSource to Media Element 
        mediaElement.SetMediaStreamSource(mss); 

        // Close control panel after file open 
        Splitter.IsPaneOpen = false; 
       } 
       else 
       { 
        DisplayErrorMessage("Cannot open media"); 
       } 
      } 
      catch (Exception ex) 
      { 
       DisplayErrorMessage(ex.Message); 
      } 

P.S:我已經在頂部使用了ffmpeginterop語句,所以沒有發生編譯器時間錯誤。

編輯 問題只是我的機器上發生的,暫時運行在64位模式和釋放模式的應用解決了這個問題。爲什麼在調試模式下出現問題仍然未知。

回答

1

一種可能性是......您忘了將解碼器.dll添加到您的項目中。如果添加了dll,則.csproj具有以下行。

<ItemGroup> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\avcodec-57.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\avdevice-57.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\avfilter-6.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\avformat-57.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\avutil-55.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\swresample-2.dll" /> 
     <Content Include="$(SolutionDir)ffmpeg\Build\Windows10\$(PlatformTarget)\bin\swscale-4.dll" /> 

注 - 實際路徑是取決於你的開發環境。

您可以檢查包含在FFmpegInterop項目中的示例項目。示例.csproject具有相同的部分。

https://github.com/Microsoft/FFmpegInterop/tree/master/Samples/SamplesWin10/MediaPlayerCS

+0

如何檢查csproj文件?我的意思是不是一個項目文件?如何以文本形式打開它,就像您在帖子中顯示的一樣,以確認它是否具有這些dll參考?如果你問我是否在我的項目文件夾中有dll文件,那麼不,我沒有他們bcz我從金塊下載庫,它沒有依賴關係。 – touseef

+0

這是我誤解了。我以爲你從源頭使用FFmpegInterop建築物。如果你使用NuGet包,是的,你不必修改.csproj來添加解碼器DLL。之後,我嘗試重新創建您的問題。我創建了一個簡單的UWP項目並添加了FFmpegInterop.UWP.1.0.3。但是,它運行良好,沒有錯誤。對不起,但我不知道。 – pnp0a03

1

我測試了我的身邊你的代碼。我創建了一個空白的uwp應用程序,並安裝了FFmpegInterop.UWP 1.0.3 nuget包。然後使用您的代碼片段播放本地mp4媒體文件。這可以很好地工作,我不能重現你的問題。由於你的代碼片段不是全部,因此這是一個可以成功運行的完整演示,你可以測試並試圖找出問題所在。

XAML代碼

<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <MediaElement x:Name="mediaElement" Height="400" Width="400">    
    </MediaElement> 
    <Button x:Name="btnplay" Click="btnplay_Click" Content="play"></Button> 
</StackPanel> 

代碼背後

private async void btnplay_Click(object sender, RoutedEventArgs e) 
{ 
    FileOpenPicker openPicker = new FileOpenPicker(); 
    openPicker.ViewMode = PickerViewMode.Thumbnail; 
    openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
    openPicker.FileTypeFilter.Add(".mp3"); 
    openPicker.FileTypeFilter.Add(".mp4"); 
    openPicker.FileTypeFilter.Add(".mkv"); 
    StorageFile file = await openPicker.PickSingleFileAsync(); 
    using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read)) 
    { 
     try 
     { 
      // Instantiate FFmpegInteropMSS using the opened local file stream 
      var FFmpegMSS = FFmpegInteropMSS.CreateFFmpegInteropMSSFromStream(readStream, false, false); 
      MediaStreamSource mss = FFmpegMSS.GetMediaStreamSource(); 
      if (mss != null) 
      { 
       // Pass MediaStreamSource to Media Element 
       mediaElement.SetMediaStreamSource(mss); 
       // Close control panel after file open 
       //Splitter.IsPaneOpen = false; 
      } 
      else 
      { 
       System.Diagnostics.Debug.WriteLine("Cannot open media"); 
      } 
     } 
     catch (Exception ex) 
     { 
      System.Diagnostics.Debug.WriteLine((ex.Message)); 
     } 
    } 
} 

我在本地機器窗口測試10構建14393.更多細節請參考this articlehere與您可能會嘗試引用的類似問題。

+0

我也有構建14393和我複製粘貼你的XAML和C#,仍然得到完全相同的錯誤,如以前:(它只是沒有任何意義,你調試什麼模式?x84或x64在Visual Studio中爲這個項目? – touseef

+0

在Visual Studio中將版本轉換爲x63,現在它運行的是mp4文件,但它顯示的視頻爲2,3秒,然後媒體seekbar直接播放到視頻的末尾,如果再次按播放按鈕,則解碼失敗錯誤寫在媒體播放器上 – touseef

+0

@touseef我無法重現只播放2-3秒的問題,請檢查您的mp4文件本身是否有問題。重複播放可能會導致錯誤,因爲該文件已被打開供閱讀。 –