I've been trying to play video in my wpf windows application, tried video play using MediaElement just to receive wired behavior (mentioned in the other thread). Now I am trying to use MediaPlayer using the following code -
MediaPlayer player = new MediaPlayer();
player.Open(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative));
VideoDrawing aVideoDrawing = new VideoDrawing();
aVideoDrawing.Rect = new Rect(0, 0, 100, 100);
aVideoDrawing.Player = player;
player.Play();
Th problem is that, I am not able to see any video. Am I doing anything wrong ?
-
-
Are you sure the Uri to the given file is really pointing to the file? Not that you give the media player a file that is not there!
-
Yes ofcourse, the file does exists at the location and if I provide same URI to MEdiaElement it does play the video.

-
kaul wrote:
MediaPlayer player = new MediaPlayer();
player.Open(new Uri(@"sampleMedia\xbox.wmv", UriKind.Relative));
VideoDrawing aVideoDrawing = new VideoDrawing();
aVideoDrawing.Rect = new Rect(0, 0, 100, 100);
aVideoDrawing.Player = player;
player.Play();
Th problem is that, I am not able to see any video. Am I doing anything wrong ?
Haven't used MediaPlayer and VideoDrawing, but do you not need to add the VideoDrawing to something, or tell it where to paint?
-
Rossj wrote:
Haven't used MediaPlayer and VideoDrawing, but do you not need to add the VideoDrawing to something, or tell it where to paint?
Rossj is on the right track, this question was asked in the forums.
It ain't easy, basicly you need a rectangle in your xaml, and then refer to that rectangle in code. Notice the Click on the button is set to the Name of the playMedia event.
XAML:
<StackPanel>
<Rectangle x:Name="VideoRect" Height="220"
RadiusX="10" RadiusY="10"/>
<Button Click="playMedia" VerticalAlignment="Bottom"
Content="Play" Height="25"/>
</StackPanel> Code:
public void playMedia(object sender, RoutedEventArgs e) {
MediaPlayer player = new MediaPlayer();
player.Open( new Uri( @"Movie.wmv", UriKind.Relative ) );VideoDrawing aVideoDrawing = new VideoDrawing();
aVideoDrawing.Player = player;
aVideoDrawing.Rect = new Rect( 0, 0, 222, 222 );
// Needs a Rect associated With the VideoDrawing but size is
// Determinted by the xaml Code.
DrawingBrush dBrush = new DrawingBrush( aVideoDrawing );
VideoRect.Fill = dBrush;// Play the video once.
player.Play();
} -
Thanks a lot for this well explained demo !! Its working for me now

Thread Closed
This thread is kinda stale and has been closed but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.