0
在我的應用程序中,我從數據庫獲取視頻文件爲byte [],我的要求就像使用WPF媒體元素播放該視頻文件。 只是想知道什麼是最好的和優雅的方式來做到這一點。MediaElement查詢
在我的應用程序中,我從數據庫獲取視頻文件爲byte [],我的要求就像使用WPF媒體元素播放該視頻文件。 只是想知道什麼是最好的和優雅的方式來做到這一點。MediaElement查詢
你可以使用這個功能,使用媒體元素在WPF中播放視頻...
給了它最好的結果,我已經使用這個...
請通過這個鏈接瞭解更多信息在how to play video in wpf uisng media element
/// <summary>
/// Handles Drop Event for Media Items.
/// </summary>
private void Media_Drop(object sender, DragEventArgs e)
{
string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true)
as string[];
//keep a dictionary of added files
foreach (string f in fileNames)
{
if (IsValidMediaItem(f))
mediaItems.Add(f.Substring(f.LastIndexOf(@"\")+1),
new MediaItem(@f,0));
}
//now add to the list
foreach (MediaItem mi in mediaItems.Values)
lstMediaItems.Items.Add(mi);
// Mark the event as handled,
// so the control's native Drop handler is not called.
e.Handled = true;
}
/// <summary>
/// check to see if dragged items are valid
/// </summary>
/// <returns>true if filename is valid</returns>
private bool IsValidMediaItem(string filename)
{
bool isValid = false;
string fileExtesion = filename.Substring(filename.LastIndexOf("."));
foreach (string s in MediaItem.allowableMediaTypes)
{
if (s.Equals(fileExtesion,
StringComparison.CurrentCultureIgnoreCase))
isValid = true;
}
return isValid;
}
我希望它會幫助你...
感謝您的回答,但我的問題是不同的。我從數據庫中獲取字節數組,我的問題就像我必須對byte []做的事情,以便我可以播放視頻而不會出現任何性能問題。一種解決方案就像將字節[]轉換爲內存流並播放視頻,但我認爲這不是正確的方法,因此不建議將整個視頻加載到內存流中。那麼做到這一點的最好和最優雅的方式是什麼? –