在我的应用程序中,我从数据库中以byte[]格式获取视频文件,我的要求是使用WPF media元素播放该视频文件。我只想知道什么是最好的和优雅的方式。
发布于 2011-10-29 21:16:11
您可以使用此函数通过媒体元素在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;
}我希望它能帮助你。
https://stackoverflow.com/questions/7939101
复制相似问题