如何拉伸System.Windows.Media.MediaPlayer?

时间:2013-02-17 07:23:33

标签: c# wpf media-player

我正在尝试使用MediaPlayer类显示视频。 codeProject我正在看一个例子。

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MediaTimeline timeline = 
              new MediaTimeline(new Uri("airplane.mpg", UriKind.Relative));
            timeline.RepeatBehavior = RepeatBehavior.Forever;
            MediaClock clock = timeline.CreateClock();
            MediaPlayer player = new MediaPlayer();
            player.Clock = clock;
            VideoDrawing drawing = new VideoDrawing();
            drawing.Rect = new Rect(0, 0, 300, 200);
            drawing.Player = player;
            DrawingBrush brush = new DrawingBrush(drawing);
            this.Background = brush;
        }
    }

一切都很好,但我不知道如何延长视频。除了使用视图,有谁知道如何使用System.Windows.Media.Stretch来更改视频大小?

(请不要建议使用MediaElement或WpfMediakit或其他类或外部库,此问题专门针对System.Windows.Media.MediaPlayer)。

1 个答案:

答案 0 :(得分:0)

好的,我很笨,实际上很容易,

    drawing.Rect = new Rect(0, 0, player.NaturalVideoWidth , player.NaturalVideoHeight );
    brush.Stretch =  System.Windows.Media.Stretch.SomeStretchEnum