Click here to Skip to main content
15,887,596 members
Articles / Programming Languages / C#

Cool Media Player with Silverlight

Rate me:
Please Sign up or sign in to vote.
2.36/5 (10 votes)
7 Sep 2008CPOL 50.2K   1.4K   17   9
Demo Media player
MediaPlayer

Introduction

This article discusses about using MediaElement to play a multimedia file in Silverlight. It has a simple button, example: play, pause, replay, slide time, fullscreen, mute, unmute and slide volume.

Using the Code

C#

C#
namespace MediaPlayer
{
    [ScriptableType]
    public partial class Page : UserControl
    {
        private DispatcherTimer timer;
        private bool isSliderTimeLock{ get; set;}
        private double currentMediaVolume;
        private double old_Height;
        private double old_Width;
        private double old_MediaHeight;
        private double old_MediaWidth;
        private System.Windows.Interop.SilverlightHost host;

        public Page(string source, bool autoPlay)
        {
            InitializeComponent();

            #region Kiem tra file input la video hay audio de goi 
		giao dien player phu hop
            string[] strings = source.Split('.');
            int count = strings.Length - 1;
            if ((strings[count].StartsWith("wma")) || (strings[count].StartsWith("mp3")))
            {
                VisualStateManager.GoToState(this, "Audio", true);
            }
            else
            {
                VisualStateManager.GoToState(this, "Video", true);
            }
            mePlayer.Source = new Uri(source, UriKind.Relative);
            mePlayer.AutoPlay = autoPlay;
            #endregion

            Loaded += new RoutedEventHandler(Page_Loaded);            
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            isSliderTimeLock = false;
            sliderVolume.Value = 1;
            btnReplay.Opacity = 0.3;
            old_Width = this.Width;
            old_Height = this.Height;
            old_MediaWidth = mePlayer.Width;
            old_MediaHeight = mePlayer.Height;
            host = Application.Current.Host;
            host.Content.IsFullScreen = true;

            HtmlPage.RegisterScriptableObject("mediaPlayer", this);           

            btnPlay.Checked += new RoutedEventHandler(btnPlay_Checked);
            btnPlay.Unchecked += new RoutedEventHandler(btnPlay_Unchecked);
            
            mePlayer.CurrentStateChanged += new RoutedEventHandler
					(mePlayer_CurrentStateChanged);

            //Event MouseLeftButtonDonw and MouseLefButtonUp of 
            //Slider is no longer available in beta 2 --> that's messed
            //sliderTime.MouseLeftButtonDown += new MouseButtonEventHandler
            //(sliderTime_MouseLeftButtonDown);
            //sliderTime.MouseLeftButtonUp += new MouseButtonEventHandler
            //(sliderTime_MouseLeftButtonUp);
            sliderTime.ThumbDragStarted += new EventHandler<EventArgs>
					(sliderTime_ThumbDragStarted);
            sliderTime.ThumbDragCompleted += new EventHandler<EventArgs>
					(sliderTime_ThumbDragCompleted);

            sliderVolume.ValueChanged += new RoutedPropertyChangedEventHandler
					<double>(sliderVolume_ValueChanged);

            btnReplay.Click += new RoutedEventHandler(btnReplay_Click);

            btnMute.Checked += new RoutedEventHandler(btnMute_Checked);
            btnMute.Unchecked += new RoutedEventHandler(btnMute_Unchecked);

            btnFull.Click += new RoutedEventHandler(btnFull_Click);


            btnFullScreen.Click += new RoutedEventHandler(btnFullScreen_Click);
            host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

            mePlayer.MediaEnded += new RoutedEventHandler(mePlayer_MediaEnded);

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(50);
            timer.Tick += new EventHandler(timer_Tick);          
        }

        void Content_FullScreenChanged(object sender, EventArgs e)
        {
            if (host.Content.IsFullScreen)
            {
                userControl.Width = Application.Current.Host.Content.ActualWidth;
                userControl.Height = Application.Current.Host.Content.ActualHeight;

                mePlayer.Width = Application.Current.Host.Content.ActualWidth;
                mePlayer.Height = Application.Current.Host.Content.ActualHeight;
            }
            else
            {
                userControl.Width = old_Width;
                userControl.Height = old_Height;

                mePlayer.Width = old_MediaWidth;
                mePlayer.Height = old_MediaHeight;
            }
        }

        void btnFullScreen_Click(object sender, RoutedEventArgs e)
        {
            Application.Current.Host.Content.IsFullScreen = 
			!Application.Current.Host.Content.IsFullScreen;
        }

        void btnFull_Click(object sender, RoutedEventArgs e)
        {
            if(btnFull.Content.Equals("Audio"))
            {
                VisualStateManager.GoToState(this, "Audio", true);
                btnFull.Content = "Video";
            }
            else
            {
                VisualStateManager.GoToState(this, "Video", true);
                btnFull.Content = "Audio";
            }
        }

        void btnMute_Unchecked(object sender, RoutedEventArgs e)
        {
            mePlayer.Volume = currentMediaVolume;
            btnMute.Content = "Mute";
        }

        void btnMute_Checked(object sender, RoutedEventArgs e)
        {
            btnMute.Content = "Unmute";
            currentMediaVolume = mePlayer.Volume;
            mePlayer.Volume = 0;
        }

        void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            if (btnReplay.Opacity.Equals(1))
            {
                mePlayer.Position = TimeSpan.FromMilliseconds(0);
                mePlayer.Play();
            }
        }

        void sliderVolume_ValueChanged(object sender, 
		RoutedPropertyChangedEventArgs<double> e)
        {
            mePlayer.Volume = sliderVolume.Value;
        }

        

        void sliderTime_ThumbDragCompleted(object sender, EventArgs e)
        {
            //tbTime.Text = "mouse up" + isSliderTimeLock.ToString();
            isSliderTimeLock = false;
            mePlayer.Position = TimeSpan.FromMilliseconds
	     (mePlayer.NaturalDuration.TimeSpan.TotalMilliseconds * sliderTime.Value);
        }

        void sliderTime_ThumbDragStarted(object sender, EventArgs e)
        {
            isSliderTimeLock = true;
        }

        void mePlayer_MediaEnded(object sender, RoutedEventArgs e)
        {
            mePlayer.Position = TimeSpan.FromMilliseconds(0);
            sliderTime.Value = 0;
            btnPlay.IsChecked = false;
            //btnPlay_Unchecked(sender, e);
            btnReplay.Opacity = 1;
        }

        void mePlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
        {
            if(mePlayer.CurrentState == MediaElementState.Playing)
            {
                timer.Start();
            }
            else
            {
                timer.Stop();
            }
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if((mePlayer.NaturalDuration.TimeSpan.TotalSeconds > 0) && 
					(isSliderTimeLock == false))
            {
                //tbTime.Text = string.Format("{0:00}:{1:00}", 
                //mePlayer.Position.Minutes, mePlayer.Position.Seconds)+
                //"/"+mePlayer.NaturalDuration.TimeSpan.TotalSeconds.ToString();
                tbTime.Text = string.Format("{0:00}:{1:00}", 
			mePlayer.Position.Minutes, mePlayer.Position.Seconds);
                sliderTime.Value = mePlayer.Position.TotalSeconds/
			mePlayer.NaturalDuration.TimeSpan.TotalSeconds;
            }
        }

        void btnPlay_Unchecked(object sender, RoutedEventArgs e)
        {
            mePlayer.Pause();
            btnPlay.Content = "Play";
        }

        void btnPlay_Checked(object sender, RoutedEventArgs e)
        {
            mePlayer.Play();
            btnPlay.Content = "Pause";
        }
      
        #region Method for interacting with javascript (API)
        [ScriptableMember]
        public double getDoubleValue()
        {
            return (double)43;
        }

        [ScriptableMember]
        public void FullScreen()
        {
            userControl.Width = Application.Current.Host.Content.ActualWidth;
            userControl.Height = Application.Current.Host.Content.ActualHeight;

            mePlayer.Width = Application.Current.Host.Content.ActualWidth;
            mePlayer.Height = Application.Current.Host.Content.ActualHeight;
        }
        [ScriptableMember]
        public void Pause()
        {
            btnPlay.Content = "Play";
            btnPlay.IsChecked = true;
            mePlayer.Pause();
        }
        [ScriptableMember]
        public void Play()
        {
            btnPlay.Content = "Pause";
            btnPlay.IsChecked = false;
            mePlayer.Play();
        }
        [ScriptableMember]
        public void Stop()
        {
            btnPlay.Content = "Play";
            btnPlay.IsChecked = true;
            mePlayer.Stop();
            sliderTime.Value = 0;
        }
        [ScriptableMember]
        public void Volume(double vol)
        {
            mePlayer.Volume = vol;
            sliderVolume.Value = vol;
        }
        [ScriptableMember]
        public void Seek(double pos)
        {
            if ((mePlayer.NaturalDuration.TimeSpan.TotalSeconds > pos) && (pos >= 0))
            {
                mePlayer.Position = TimeSpan.FromSeconds(pos);
                sliderTime.Value = 
                     mePlayer.Position.TotalSeconds / 
			mePlayer.NaturalDuration.TimeSpan.TotalSeconds;
            }
        }
        [ScriptableMember]
        public void LoadSource(string url)
        {
            //Stop();
            mePlayer.Source = new Uri(url, UriKind.Relative);
        } 
        #endregion
    }
C#
public class CustomSlider:System.Windows.Controls.Slider
    {
        public CustomSlider():base()
        {
            DefaultStyleKey = typeof (CustomSlider);
        }
        /// <summary>

        /// Thrown when the thumb has been clicked, and dragging is initiated

        /// </summary>
        public event EventHandler<EventArgs> ThumbDragStarted;

        /// <summary>

        /// Thrown when the thumb has been released

        /// </summary>
        public event EventHandler<EventArgs> ThumbDragCompleted;
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            //Set up drag event handlers
            Thumb thumb = this.GetTemplateChild("HorizontalThumb") as Thumb; 
			if (thumb != null)
            {

                thumb.DragStarted += new DragStartedEventHandler(thumb_DragStarted);
                thumb.DragCompleted += new DragCompletedEventHandler(thumb_DragCompleted);
            }
        }

        void thumb_DragCompleted(object sender, DragCompletedEventArgs e)
        {
            OnThumbDragCompleted(this, new EventArgs());
        }
        void thumb_DragStarted(object sender, DragStartedEventArgs e)
        {
            OnThumbDragStarted(this, new EventArgs());
        }
        public virtual void OnThumbDragStarted(object sender, EventArgs e)
        {
            if (ThumbDragStarted != null)
                ThumbDragStarted(sender, e);
        }
        protected virtual void OnThumbDragCompleted(object sender, EventArgs e)
        {
            if (ThumbDragCompleted != null)

                ThumbDragCompleted(sender, e);
        }
    }
}

Points of Interest

I'm very surprised at Slider in Silverlight beta 2, it have MouseLeftButtonUp and MouseLeftButtonDown events, but these don't work. I have to inherit Slider class and code the above event by hand.

History

  • 7th September, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
VickyC#10-Nov-10 18:01
VickyC#10-Nov-10 18:01 
GeneralHihihi chào anh Minh! Pin
Luyen Ha25-Jul-10 3:25
Luyen Ha25-Jul-10 3:25 
GeneralBecause it gives this error when running your project in VisualStudio 2008 Pin
LuizItatiba20-Aug-09 16:43
LuizItatiba20-Aug-09 16:43 
When testing your application in Visual Studio 2008 the following error occurred

System.Windows.Markup.XamlParseException occurred
   Message="Unknown attribute Duration on element VisualTransition. [Line: 154 Position: 40]"
   LineNumber=154
   LinePosition=40
   StackTrace:
         at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
         at MediaPlayer.Page.InitializeComponent()
         at MediaPlayer.Page..ctor(String source, Boolean autoPlay)
   InnerException:

To test it put a link on my video. Asx but the source below it is not recognizing the Duration property and there gives as outlined in my VisualStudio 2008 and my XP machine that I installed is only Silverlight2.0

source here


<pre>&lt;UserControl x:Class="MediaPlayer.Page"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Width="528" Height="416" xmlnsBig Grin | :-D ="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:MediaPlayer="clr-namespace:MediaPlayer" mc:Ignorable="d" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" x:Name="userControl"&gt;

     &lt;UserControl.Resources&gt;
          &lt;Style x:Key="SliderStyleForCustomSlider" TargetType="Slider"&gt;
               &lt;Setter Property="Template"&gt;
                    &lt;Setter.Value&gt;
                         &lt;ControlTemplate TargetType="Slider"&gt;
                              &lt;Grid x:Name="Root"&gt;
                                   &lt;Grid.Resources&gt;
                                        &lt;ControlTemplate x:Key="RepeatButtonTemplate"&gt;
                                             &lt;Grid x:Name="Root" Opacity="0" Background="Transparent"/&gt;
                                        &lt;/ControlTemplate&gt;
                                   &lt;/Grid.Resources&gt;
                                   &lt;vsm:VisualStateManager.VisualStateGroups&gt;
                                        &lt;vsm:VisualStateGroup x:Name="CommonStates"&gt;
                                             &lt;vsm:VisualStateGroup.Transitions&gt;
                                                  &lt;vsm:VisualTransition Duration="0"/&gt;
                                             &lt;/vsm:VisualStateGroup.Transitions&gt;
                                             &lt;vsm:VisualState x:Name="Normal"/&gt;
                                             &lt;vsm:VisualState x:Name="MouseOver"/&gt;
                                             &lt;vsm:VisualState x:Name="Disabled"&gt;
                                                  &lt;Storyboard&gt;
                                                       &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetName="Root" Storyboard.TargetProperty="(UIElement.Opacity)"&gt;
                                                            &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/&gt;
                                                       &lt;/DoubleAnimationUsingKeyFrames&gt;
                                                  &lt;/Storyboard&gt;
                                             &lt;/vsm:VisualState&gt;
                                        &lt;/vsm:VisualStateGroup&gt;
                                        &lt;vsm:VisualStateGroup x:Name="FocusStates"&gt;
                                             &lt;vsm:VisualStateGroup.Transitions&gt;
                                                  &lt;vsm:VisualTransition Duration="0"/&gt;
                                             &lt;/vsm:VisualStateGroup.Transitions&gt;
                                             &lt;vsm:VisualState x:Name="Unfocused"/&gt;
                                             &lt;vsm:VisualState x:Name="Focused"&gt;
                                                  &lt;Storyboard&gt;
                                                       &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="(UIElement.Opacity)"&gt;
                                                            &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/&gt;
                                                       &lt;/DoubleAnimationUsingKeyFrames&gt;
                                                  &lt;/Storyboard&gt;
                                             &lt;/vsm:VisualState&gt;
                                        &lt;/vsm:VisualStateGroup&gt;
                                   &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
                                   &lt;Grid x:Name="HorizontalTemplate"&gt;
                                        &lt;Grid.ColumnDefinitions&gt;
                                             &lt;ColumnDefinition Width="Auto"/&gt;
                                             &lt;ColumnDefinition Width="Auto"/&gt;
                                             &lt;ColumnDefinition Width="*"/&gt;
                                        &lt;/Grid.ColumnDefinitions&gt;
                                        &lt;Rectangle Height="3" Margin="5,0,5,0" Grid.Column="0" Grid.ColumnSpan="3" Fill="#FFE6EFF7" Stroke="Black" StrokeThickness="0.5"/&gt;
                                        &lt;RepeatButton x:Name="HorizontalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="0"/&gt;
                                        &lt;Thumb Height="24" x:Name="HorizontalThumb" Width="24" Grid.Column="1" Foreground="#FF000000" Template="{StaticResource ThumbControlTemplateTime}"/&gt;
                                        &lt;RepeatButton x:Name="HorizontalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Column="2"/&gt;
                                   &lt;/Grid&gt;
                                   &lt;Grid x:Name="VerticalTemplate" Visibility="Collapsed"&gt;
                                        &lt;Grid.RowDefinitions&gt;
                                             &lt;RowDefinition Height="*"/&gt;
                                             &lt;RowDefinition Height="Auto"/&gt;
                                             &lt;RowDefinition Height="Auto"/&gt;
                                        &lt;/Grid.RowDefinitions&gt;
                                        &lt;Rectangle Margin="0,5,0,5" Width="3" Grid.Row="0" Grid.RowSpan="3" Fill="#FFE6EFF7" Stroke="Black" StrokeThickness="0.5"/&gt;
                                        &lt;RepeatButton x:Name="VerticalTrackLargeChangeDecreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="2"/&gt;
                                        &lt;Thumb Height="11" x:Name="VerticalThumb" Width="18" Grid.Row="1"/&gt;
                                        &lt;RepeatButton x:Name="VerticalTrackLargeChangeIncreaseRepeatButton" IsTabStop="False" Template="{StaticResource RepeatButtonTemplate}" Grid.Row="0"/&gt;
                                   &lt;/Grid&gt;
                                   &lt;Rectangle x:Name="FocusVisual" IsHitTestVisible="false" Opacity="0" Stroke="#666666" StrokeDashArray=".2 5" StrokeDashCap="Round"/&gt;
                              &lt;/Grid&gt;
                         &lt;/ControlTemplate&gt;
                    &lt;/Setter.Value&gt;
               &lt;/Setter&gt;
          &lt;/Style&gt;

          &lt;ControlTemplate x:Key="ButtonControlTemplateFullScreen" TargetType="Button"&gt;
               &lt;Grid Width="64" Height="56"&gt;
                    &lt;vsm:VisualStateManager.VisualStateGroups&gt;
                         &lt;vsm:VisualStateGroup x:Name="FocusStates"&gt;
                              &lt;vsm:VisualState x:Name="Unfocused"&gt;
                                   &lt;Storyboard/&gt;
                              &lt;/vsm:VisualState&gt;
                              &lt;vsm:VisualState x:Name="Focused"&gt;
                                   &lt;Storyboard/&gt;
                              &lt;/vsm:VisualState&gt;
                         &lt;/vsm:VisualStateGroup&gt;
                         &lt;vsm:VisualStateGroup x:Name="CommonStates"&gt;
                              &lt;vsm:VisualState x:Name="MouseOver"&gt;
                                   &lt;Storyboard&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgFullScreen" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.268"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgFullScreen" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.268"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgFullScreen" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="-0.571"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgFullScreen" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.5"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgReturn" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.268"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgReturn" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="1.268"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgReturn" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.571"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                        &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="imgReturn" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&gt;
                                             &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="-0.5"/&gt;
                                        &lt;/DoubleAnimationUsingKeyFrames&gt;
                                   &lt;/Storyboard&gt;
                              &lt;/vsm:VisualState&gt;
                              &lt;vsm:VisualState x:Name="Pressed"&gt;
                                   &lt;Storyboard/&gt;
                              &lt;/vsm:VisualState&gt;
                              &lt;vsm:VisualState x:Name="Disabled"&gt;
                                   &lt;Storyboard/&gt;
                              &lt;/vsm:VisualState&gt;
                              &lt;vsm:VisualState x:Name="Normal"&gt;
                                   &lt;Storyboard/&gt;
                              &lt;/vsm:VisualState&gt;
                         &lt;/vsm:VisualStateGroup&gt;
                    &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
                    &lt;Image x:Name="imgFullScreen" Source="Images/FullScreen.png" RenderTransformOrigin="0.5,0.5"&gt;
                         &lt;Image.RenderTransform&gt;
                              &lt;TransformGroup&gt;
                                   &lt;ScaleTransform/&gt;
                                   &lt;SkewTransform/&gt;
                                   &lt;RotateTransform/&gt;
                                   &lt;TranslateTransform/&gt;
                              &lt;/TransformGroup&gt;
                         &lt;/Image.RenderTransform&gt;
                    &lt;/Image&gt;
                    &lt;Image x:Name="imgReturn" Opacity="0" Source="Images/ReturnScreen.png" RenderTransformOrigin="0.5,0.5"&gt;
                         &lt;Image.RenderTransform&gt;
                              &lt;TransformGroup&gt;
                                   &lt;ScaleTransform/&gt;
                                   &lt;SkewTransform/&gt;
                                   &lt;RotateTransform/&gt;
                                   &lt;TranslateTransform/&gt;
                              &lt;/TransformGroup&gt;
                         &lt;/Image.RenderTransform&gt;
                    &lt;/Image&gt;
               &lt;/Grid&gt;
          &lt;/ControlTemplate&gt;
     &lt;/UserControl.Resources&gt;
      &lt;Grid x:Name="LayoutRoot" Background="White"&gt;
           
           &lt;vsm:VisualStateManager.VisualStateGroups&gt;
                &lt;vsm:VisualStateGroup x:Name="TypeMedia"&gt;
                     &lt;vsm:VisualStateGroup.Transitions&gt;
                          &lt;vsm:VisualTransition Duration="00:00:00.3000000"/&gt;
                     &lt;/vsm:VisualStateGroup.Transitions&gt;
                     &lt;vsm:VisualState x:Name="Video"&gt;
                          &lt;Storyboard/&gt;
                     &lt;/vsm:VisualState&gt;
                     &lt;vsm:VisualState x:Name="Audio"&gt;
                          &lt;Storyboard&gt;
                               &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="userControl" Storyboard.TargetProperty="(FrameworkElement.Height)"&gt;
                                    &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="56"/&gt;
                               &lt;/DoubleAnimationUsingKeyFrames&gt;
                               &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="userControl" Storyboard.TargetProperty="(FrameworkElement.Width)"&gt;
                                    &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="344"/&gt;
                               &lt;/DoubleAnimationUsingKeyFrames&gt;
                               &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="mePlayer" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)"&gt;
                                    &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.16"/&gt;
                               &lt;/DoubleAnimationUsingKeyFrames&gt;
                               &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="mePlayer" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)"&gt;
                                    &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="-84"/&gt;
                               &lt;/DoubleAnimationUsingKeyFrames&gt;
                               &lt;ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="mePlayer" Storyboard.TargetProperty="(UIElement.Visibility)"&gt;
                                    &lt;DiscreteObjectKeyFrame KeyTime="00:00:00"&gt;
                                         &lt;DiscreteObjectKeyFrame.Value&gt;
                                              &lt;vsm:Visibility&gt;Collapsed&lt;/vsm:Visibility&gt;
                                         &lt;/DiscreteObjectKeyFrame.Value&gt;
                                    &lt;/DiscreteObjectKeyFrame&gt;
                               &lt;/ObjectAnimationUsingKeyFrames&gt;
                               &lt;DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="mePlayer" Storyboard.TargetProperty="(UIElement.Opacity)"&gt;
                                    &lt;SplineDoubleKeyFrame KeyTime="00:00:00" Value="0"/&gt;
                               &lt;/DoubleAnimationUsingKeyFrames&gt;
                          &lt;/Storyboard&gt;
                     &lt;/vsm:VisualState&gt;
                &lt;/vsm:VisualStateGroup&gt;
           &lt;/vsm:VisualStateManager.VisualStateGroups&gt;
           &lt;Canvas HorizontalAlignment="Stretch" Margin="0,0,0,0" VerticalAlignment="Stretch" Background="#FFBBADAD" x:Name="canvasMedia"&gt;
                &lt;MediaElement Source="http://meudominiovideo/pdatrailer1silverlight.asx" Opacity="1"
                     Width="488" Height="328" OpacityMask="#FFE35353" d:LayoutOverrides="HorizontalAlignment" x:Name="mePlayer" AutoPlay="False" BufferingTime="00:00:00" Margin="0,0,0,0" Canvas.Top="8" Canvas.Left="16" RenderTransformOrigin="0.5,0.5"&gt;
                     &lt;MediaElement.RenderTransform&gt;
                          &lt;TransformGroup&gt;
                               &lt;ScaleTransform/&gt;
                               &lt;SkewTransform/&gt;
                               &lt;RotateTransform/&gt;
                               &lt;TranslateTransform/&gt;
                          &lt;/TransformGroup&gt;
                     &lt;/MediaElement.RenderTransform&gt;
                &lt;/MediaElement&gt;
           &lt;/Canvas&gt;
           
           &lt;MediaPlayer:CustomSlider Height="24" Margin="151,0,256,22" VerticalAlignment="Bottom" x:Name="sliderTime" Maximum="1" HorizontalAlignment="Stretch" MouseLeftButtonDown="sliderTime_MouseLeftButtonDown_1" Style="{StaticResource SliderStyleForCustomSlider}"/&gt;
           &lt;MediaPlayer:CustomSlider Height="24" HorizontalAlignment="Right" Margin="0,0,0,22" VerticalAlignment="Bottom" Width="48" x:Name="sliderVolume" Style="{StaticResource SliderStyleForCustomSlider}" Maximum="1"/&gt;
           &lt;TextBlock Height="24" HorizontalAlignment="Right" Margin="0,0,199,22"   VerticalAlignment="Bottom" Text="" TextWrapping="Wrap" FontSize="11" x:Name="tbTime" Width="40"/&gt;
           &lt;ToggleButton Height="56" HorizontalAlignment="Left" Margin="8,0,0,8" VerticalAlignment="Bottom" Width="60" Content="Play" x:Name="btnPlay" Template="{StaticResource ToggleButtonControlTemplatePlay}"/&gt;
           &lt;Button Height="56" HorizontalAlignment="Left" Margin="72,0,0,8" VerticalAlignment="Bottom" Width="60" Content="Replay" x:Name="btnReplay" Template="{StaticResource ButtonControlTemplateReplay}"/&gt;
           &lt;ToggleButton Height="56" HorizontalAlignment="Right" Margin="0,0,52,8" VerticalAlignment="Bottom" Width="64" Content="Mute" x:Name="btnMute" Template="{StaticResource ToggleButtonControlTemplateMute}"/&gt;
           &lt;TextBlock Height="24" Margin="88,88,148,0" VerticalAlignment="Top" Text="TextBlock" TextWrapping="Wrap" x:Name="tbDisplay" Visibility="Collapsed"/&gt;
           &lt;Button Height="24" HorizontalAlignment="Right" Margin="0,0,100,16" VerticalAlignment="Bottom" Width="36" Content="Audio" x:Name="btnFull" Visibility="Collapsed"/&gt;
           &lt;Button Height="56" HorizontalAlignment="Right" Margin="0,0,120,8" VerticalAlignment="Bottom" Content="Full Screen" x:Name="btnFullScreen" Width="64" Template="{StaticResource ButtonControlTemplateFullScreen}"/&gt;
           &lt;Thumb Height="24" HorizontalAlignment="Right" Margin="0,0,199,16" VerticalAlignment="Bottom" Width="24" Template="{StaticResource ThumbControlTemplateTime}"/&gt;
      &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>

I'm on Hold if you can help me resolve this error and I thank you

LADEF

GeneralMy vote of 1 Pin
smton9-Jul-09 15:46
smton9-Jul-09 15:46 
GeneralSilverlight UI Changes Pin
jherington1-Oct-08 20:59
jherington1-Oct-08 20:59 
GeneralRe: Silverlight UI Changes Pin
Hoàng Lê Minh2-Oct-08 1:07
Hoàng Lê Minh2-Oct-08 1:07 
GeneralRe: Silverlight UI Changes Pin
jherington2-Oct-08 6:17
jherington2-Oct-08 6:17 
GeneralThe solution does not work fine :-o Pin
MeNot29-Sep-08 0:08
MeNot29-Sep-08 0:08 
GeneralRe: The solution does not work fine :-o Pin
Hoàng Lê Minh29-Sep-08 1:02
Hoàng Lê Minh29-Sep-08 1:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.