Skip to main content

Microsoft Silverlight

Answered Question video as backgroundRSS Feed

(0)

anton berg
anton berg

Member

Member

0 points

6 Posts

video as background

Hi all ....first time with xaml, I was trying to make a simple site with video as background

I probably started out the wrong way. I was trying to create something like this http://www.julapy.com can you help me?

how do you create it in silverlight?

I wanted to use a bit longer clip but. I obviously don't know where to start please help

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: video as background

Hi Anton,

Use VideoBrush for set video as background. Pixel shaders will help you to create an effect in video as at http://www.julapy.com

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

anton berg
anton berg

Member

Member

0 points

6 Posts

Re: video as background

Hi 

I have try´d to use the MediaElement and VideoBrush but i does not play there is nothing i the browser ??

can somebody please help me

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="home.MainPage"
 Width="720" Height="480">

 <Grid x:Name="LayoutRoot" Background="White">
  <Canvas Margin="0,0,0,0"/>
  
  
  <MediaElement x:Name="home_wma" Margin="0,0,0,0" Source="/home.wma" Stretch="Fill">
   <MediaElement.Resources>
    <VideoBrush x:Key="home_wma" SourceName="home_wma"/>
   </MediaElement.Resources>
  </MediaElement>
  
 </Grid>
</UserControl>

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: video as background

Try this:

<UserControl
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 x:Class="home.MainPage"
 Width="720" Height="480">
 <Grid x:Name="LayoutRoot" Background="White">
  <Canvas Margin="0,0,0,0"/>

<MediaElement x:Name="meFilm" Source="/home.wma" IsMuted="True"
    Opacity="0.0" IsHitTestVisible="False"/>
				<TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"
                                   Text="Home page content" FontFamily="Verdana" FontSize="120" 
    FontWeight="Bold" TextWrapping="Wrap">
					<TextBlock.Foreground>
						<VideoBrush SourceName="meFilm"></VideoBrush>
					</TextBlock.Foreground>
				</TextBlock>
  
 </Grid>
</UserControl>
 

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

anton berg
anton berg

Member

Member

0 points

6 Posts

Re: video as background

Thanks Sergey,  but can´t make it loop i can only make it play once is there a way to set repeat forever ??

this is all that was needed

<Grid x:Name="LayoutRoot" Background="White">
  <MediaElement x:Name="home_wma" Margin="0,0,0,0" Source="/home.wma" Stretch="Fill" d:IsLocked="True">
   <MediaElement.Resources>
    <VideoBrush x:Key="home_wma" SourceName="home_wma"/>
   </MediaElement.Resources>
  </MediaElement>

 

 

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Re: video as background

You need to subscribe to CurrentStateChanged event of MediaElement class. Verify a state of video at handler of that event and if it stop call a Play method of MediaElement.

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

anton berg
anton berg

Member

Member

0 points

6 Posts

Re: video as background

i cant get that to work inside of blend 3. can you give me an exsample  ?

Sergey.Lutay
Sergey.L...

Contributor

Contributor

7198 points

1,340 Posts

Answered Question

Re: video as background

Try this:

- page.xaml:  

<MediaElement . . . CurrentStateChanged="MediaElement_CurrentStateChanged"

 - page.xaml.cs:

private void MediaElement_CurrentStateChanged(object sender, RoutedEventArgs e)
		{
			MediaElement me = (MediaElement)sender;
			switch (me.CurrentState)
			{
				case MediaElementState.Paused:
					me.Stop();
					me.Play();
					break;
				default:
					break;
			}
		}
 By default video is in pause state when ended.

(If this has answered your question, please click on "mark as answer" on this post. Thank you!)

Blog

Twitter

Sincerely,
Sergey Lutay

anton berg
anton berg

Member

Member

0 points

6 Posts

Re: video as background

thanks for all your help sergey ..

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities