namespace RichMediaAd
{
public partial class MediaControl : UserControl
{
//Application reference
App RichMediaApp;
//Variables for Incoming Parameters
string topText;
string topTextLink;
string bottomText;
string bottomTextLink;
string marker1, marker2, marker3;
public MediaControl()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler( Page_Loaded );
}
void Page_Loaded(object sender, RoutedEventArgs e)
{
//Application Initialization
RichMediaApp = Application.Current as App;
//Parameter Collection
foreach ( string key in RichMediaApp.InitParams.Keys )
{
//set the WMV media source having markers
if ( key.Equals( "MediaSource" ) ) MainMovieStream.Source =
new Uri(RichMediaApp.InitParams[key]);
//Text and Link attributes
if ( key.Equals( "TopText" ) ) topText = RichMediaApp.InitParams[key];
if ( key.Equals("TopTextLink") ) topTextLink = RichMediaApp.InitParams[key];
if ( key.Equals( "BottomText" ) ) bottomText = RichMediaApp.InitParams[key];
if ( key.Equals("BottomTextLink") ) bottomTextLink = RichMediaApp.InitParams[key];
//The marker parameters store the name of the animation(storyboard) passed
if ( key.Equals( "Marker1" ) ) marker1 = RichMediaApp.InitParams[key];
if ( key.Equals( "Marker2" ) ) marker2 = RichMediaApp.InitParams[key];
if ( key.Equals( "Marker3" ) ) marker3 = RichMediaApp.InitParams[key];
}
TopText.Text = topText;
BottomText.Text = bottomText;
}
///<summary>
/// This even gets raised by media element when a marker is reached
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
private void MainMovieStream_MarkerReached(object sender, TimelineMarkerRoutedEventArgs e)
{
string aniNames = "";
if ( e.Marker.Text.Equals("Marker1") )
aniNames = marker1;
elseif ( e.Marker.Text.Equals( "Marker2" ) )
aniNames = marker2;
elseif ( e.Marker.Text.Equals( "Marker3" ) )
aniNames = marker3;
if ( aniNames.IndexOf( "TopOverlayIn" ) >= 0 ) TopOverlayIn.Begin();
if ( aniNames.IndexOf( "TopOverlayOut" ) >= 0 ) TopOverlayOut.Begin();
if ( aniNames.IndexOf( "BottomOverlayIn" ) >= 0 ) BottomOverlayIn.Begin();
if ( aniNames.IndexOf( "BottomOverlayOut" ) >= 0 ) BottomOverlayOut.Begin();
}
private void BottomText_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!string.IsNullOrEmpty(bottomTextLink))
{
try
{
HtmlPage.Window.Navigate(new Uri(bottomTextLink), "_blank");
}
catch { }
}
}
private void TopText_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (!string.IsNullOrEmpty(topTextLink))
{
try
{
HtmlPage.Window.Navigate(new Uri(topTextLink), "_blank");
}
catch { }
}
}
}
}