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

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
322956
 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
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();
		}
	}
}

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

The MediaElement has got a "Position" property that takes a TimeSpan object as a value. I suppose that you can set this in the XAML file.
Random Solutions  
 
programming4us programming4us