We help IT Professionals succeed at work.
Get Started

How to make a video file play at specific scene in Silverlight, say like when time is 00:30 seconds?

ashley2009
ashley2009 asked
on
591 Views
Last Modified: 2013-11-12
Hello,

I have a question on Silverlight and XAML. I just cannot figure out, and I am not sure whether it is possible.

To explain my problem, I made a small demo file, which has two control: a textBlock and a MediaElement ( a 3 second video file).
In this example, the textBox does some animation (when the video file is invisible) for the first second, and then, I want the video file to become visible and to play, but I cannot play the video file when time is 2 second and after I make the video file visible.
I can make the video file visible, but I cannot make it play at scene 2.


I hope that I am explaining you nicely. Please help. Basically, it is like, the textBlock does some animation when the video file is invisible, and then, after 1 second, the textBlock becomes invisible, and the video file becomes visible and starts playing.

I can make the video file visible after 1 second, but the video file does not play. Please tell  me what XAML or C# code to use to solve this because I have been trying for some time. StoryBoard: Video and TextBlock Control
XAML
.......
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:System="clr-namespace:System;assembly=mscorlib"
	x:Class="SilverlightApplication1.MainPage"
	Width="640" Height="480">
	<UserControl.Resources>
		<Storyboard x:Name="Storyboard1">
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="textBlock1">
				<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:1" Value="383.333"/>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="textBlock1">
				<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
				<EasingDoubleKeyFrame KeyTime="0:0:1" Value="-101.666"/>
			</DoubleAnimationUsingKeyFrames>
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="textBlock1">
				<DiscreteObjectKeyFrame KeyTime="0:0:1">
					<DiscreteObjectKeyFrame.Value>
						<Visibility>Collapsed</Visibility>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
			</ObjectAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="clip_Small_0001_wmv">
				<EasingDoubleKeyFrame KeyTime="0:0:1" Value="-87"/>
				<EasingDoubleKeyFrame KeyTime="0:0:3" Value="-87"/>
			</DoubleAnimationUsingKeyFrames>
			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateY)" Storyboard.TargetName="clip_Small_0001_wmv">
				<EasingDoubleKeyFrame KeyTime="0:0:1" Value="-71"/>
				<EasingDoubleKeyFrame KeyTime="0:0:3" Value="-71"/>
			</DoubleAnimationUsingKeyFrames>
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="clip_Small_0001_wmv">
				<DiscreteObjectKeyFrame KeyTime="0:0:1">
					<DiscreteObjectKeyFrame.Value>
						<Visibility>Visible</Visibility>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
				<DiscreteObjectKeyFrame KeyTime="0:0:3">
					<DiscreteObjectKeyFrame.Value>
						<Visibility>Collapsed</Visibility>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
			</ObjectAnimationUsingKeyFrames>
			<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(MediaElement.AutoPlay)" Storyboard.TargetName="clip_Small_0001_wmv">
				<DiscreteObjectKeyFrame KeyTime="0">
					<DiscreteObjectKeyFrame.Value>
						<System:Boolean>False</System:Boolean>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
				<DiscreteObjectKeyFrame KeyTime="0:0:1">
					<DiscreteObjectKeyFrame.Value>
						<System:Boolean>True</System:Boolean>
					</DiscreteObjectKeyFrame.Value>
				</DiscreteObjectKeyFrame>
			</ObjectAnimationUsingKeyFrames>
		</Storyboard>
	</UserControl.Resources>

	<Grid x:Name="LayoutRoot" Background="White">
		<TextBlock x:Name="textBlock1"  HorizontalAlignment="Left" Margin="57,170,0,0" TextWrapping="Wrap" Text="TextBlock   1" VerticalAlignment="Top" RenderTransformOrigin="0.5,0.5" FontSize="22">
			<TextBlock.RenderTransform>
				<CompositeTransform/>
			</TextBlock.RenderTransform>
		</TextBlock>
		<MediaElement x:Name="clip_Small_0001_wmv" Margin="198,142,122,98" Source="/Video/clip_Small_0001.wmv" Stretch="Fill" RenderTransformOrigin="0.5,0.5" Visibility="Collapsed">
			<MediaElement.RenderTransform>
				<CompositeTransform/>
			</MediaElement.RenderTransform>
		</MediaElement>
	</Grid>
</UserControl>

C# Code Behind
................
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication1
{
	public partial class MainPage : UserControl
	{
		public MainPage()
		{
			// Required to initialize variables
			InitializeComponent();
			Storyboard1.Begin();
		}
	}
}

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE