| Author: Lalji 12 Oct 2009 | Member Level: Diamond | Rating:  Points: 2 |
Media Element Fullscreen in Silverlight code sample
Its often required to enable the fullscreen feature of an media element in silverlight. There is no straight forward way to enable that. Rather, use a video brushing, which brush the screen with the current video.
Use the xaml code as follows :
<MediaElement x:Name="media" Stretch="Uniform" Visibility="Collapsed"/>
<Rectangle x:Name="rectVideoBrush" Stretch="Uniform" Visibility="Collapsed">
<Rectangle.Fill>
<VideoBrush x:Name="mediaBrush" SourceName="media" Stretch="Uniform"/>
</Rectangle.Fill>
</Rectangle>
"media" is the media element which is set the source of the video brush named “mediaBrush”. On the full screen event trigger. the video brush brushes the screen uniformly causing the
“fullscreen” effect.
Attach the event at page load of the silverlight page :
this.showcaseMediaPlayer.FullScreenEventHandler += new RoutedEventHandler(this.FullscreenChange);
The event is triggered at the click of the full screen button the media control.
Essentially the event set the video brush media (“media”) attributes.
Event Trigger:
/// <summary>
/// Event handling the fullscreen change event.
/// </summary>
/// <param name="sender">Sender of the event.</param>
/// <param name="e">Event arguments.</param>>
private void FullscreenChange(object sender, EventArgs e)
{
Application.Current.Host.Content.IsFullScreen = true;
this.videoPosition = this.mediaPlayer.VideoPosition;
this.volume = this.mediaPlayer.Volume;
this.playerCurrentState = this.showcaseMediaPlayer.PlayerCurrentState;
}
The media is set as the media player state so that the fullscreen seems seamless.
On “Escape” of the full screen, the videobrush get back to normal form and the media player continues playing.
|
| Author: NekkantiDivya 12 Oct 2009 | Member Level: Gold | Rating:  Points: 2 |
Hi Lalji,
Thanks for your reply.
I tried your solution but have some doubts in it.
1. what is showcaseMediaPlayer? Is it a media element or media player? 2. Are showcaseMediaPlayer and media are two different controls? 3. I am not getting videoPosition or palyercurrentstate etc methods. What are they? 4. In my application I have a group of videos(nearly 6). All these are a single user control(video.xaml) which is user repeatedly and this adding usercontols is done in MainPage.xaml, then this is used in Home.aspx page. Now when we click on the button in the usercontrol it should be fullscreened.
If you have any idea to solve them or need any clarification please reply me.
Thanks in advance.
|