ComponnetOne Silverlight 和 WPF 平台提供了视频播放控件 C1MediaPlayer。可以在应用中添加视频播放功能,增强应用的可交互性。本篇文章是一篇基础应用文章-将阐述如何使用 C1MediaPlayer 播放视频文件。对于刚刚接触ComponnentOne控件套包的用户将有所帮助。下面分步讲解使用方法:

1.在 XMAL 页面添加 C1MediaPlayer 控件。

  1:  <c1:C1MediaPlayer  Height="800" VerticalAlignment="Top" Name="c1mediaplayer"/>

 

2.添加 Button 并且调用 Click 事件调用 OpenFileDialog 选择文件:

  1: <Button Width="70" Height="20" Content="选择文件" VerticalAlignment="Bottom" Click="Button_Click"/>

 

3.Button Click 事件中选择文件代码如下:

  1:         private void Button_Click(object sender, RoutedEventArgs e)
  2:         {
  3:             OpenFileDialog op = new OpenFileDialog()
  4:             {
  5:                 Filter = "Video files(*.wmv)|*.wmv|All Files(*.*)|*.*"
  6:             };
  7:             
  8:             if (op.ShowDialog()==true)
  9:             {
 10:                 //读取视频文件流
 11:                 FileStream stream = op.File.OpenRead();
 12: 
 13:                 //添加视频项
 14:                 C1MediaItem plI = new C1MediaItem();
 15:                 plI.MediaStream = stream;
 16:                 c1mediaplayer.Items.Add(plI);
 17: 
 18:                 //自动播放视频
 19:                 c1mediaplayer.Play();
 20:             }
 21:         }

 

效果图:

 

Demo1

 

最后给出 C1MediaPlayer 支持的文件格式:

支持如下视频格式:

•Raw Video
•YV12 - YCrCb(4:2:0)
•RGBA - 32 bit Alpha Red, Green, Blue
•WMV, MV2, and MV3 ( Windows Media Video 7, 8, and 9)
•Supports Simple and Main Profiles
•Supports only progressive (non-interlaced) content.
•WMVA: Windows Media Video Advanced Profile, non-VC-1.
•WVC1: Windows Media Video Advanced Profile, VC-1.
•Supports Advanced Profile.
•Supports only progressive (non-interlaced) content.
•H264 (ITU-T H.264 / ISO MPEG-4 AVC).

支持如下音频格式:
•“1” - WAV format.
•"353" - Microsoft Windows Media Audio v7, v8 and v9.x Standard (WMA Standard).
•"354" - Microsoft Windows Media Audio v9.x and v10 Professional (WMA Professional).
•"85" - ISO MPEG-1 Layer III (MP3).
•"255" - ISO Advanced Audio Coding (AAC).

 

 

Demo 下载:vs2010 + silverlight 5.0 + Studio for Silverlight 2013V2.5 + C#