locked
help me plz!! RRS feed

  • Question

  • I found a tutorial on the enternet about makeing a video player in silverlight 2.0 but if I debug it it dons't show me te movie that I added :(

    I hope some 1 can help me pls! already thanks :) 

     page.xaml

    <UserControl x:Class="movie_op_site.Page"
        xmlns="http://schemas.microsoft.com/client/2007"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
        <Grid x:Name="LayoutRoot" >
           
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="30" />
            </Grid.RowDefinitions>
           
            <Grid Grid.Row="0" Background="black">
                <MediaElement x:Name="VideoElement" Source="Bear.wmv" Height="480" Width="720" />
            </Grid>
           
            <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
                <ToggleButton x:Name="btnPlayPause" Content="Pause" Width="75" Height="25" />
               
                <Slider x:Name="sliderScrubber" Width="250" Minimum="0" Maximum="1" Margin="5,0,0,0" />
               
                <TextBlock x:Name="txtVideoPosition" Margin="5,0,0,0" />
               
            </StackPanel>
        </Grid>
    </UserControl>
     

     page.xaml.cs

    sing System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;

    using System.Windows.Threading;

    namespace movie_op_site
    {
        public partial class Page : UserControl
        {
            public DispatcherTimer timer;

            public Page()
            {
                InitializeComponent();

                btnPlayPause.Checked +=new RoutedEventHandler(btnPlayPause_Checked);
                btnPlayPause.Unchecked += new RoutedEventHandler(btnPlayPause_Unchecked);

                VideoElement.CurrentStateChanged += new RoutedEventHandler(VideoElement_CurrentStateChanged);

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

            void timer_Tick(object sender, EventArgs e)
            {
                if (VideoElement.NaturalDuration.TimeSpan.TotalSeconds > 0)
                {
                    txtVideoPosition.Text =
                        string.Format("{0:00}:{1:00}", VideoElement.Position.Minutes, VideoElement.Position.Seconds);

                    sliderScrubber.Value = VideoElement.Position.TotalSeconds /
                        VideoElement.NaturalDuration.TimeSpan.TotalSeconds;
                }
            }

            void VideoElement_CurrentStateChanged(object sender, RoutedEventArgs e)
            {
                if (VideoElement.CurrentState == MediaElementState.Playing)
                {
                    timer.Start();
                }
                else
                {
                    timer.Stop();
                }
            }
            private void btnPlayPause_Checked(object sender, RoutedEventArgs e)
            {
                VideoElement.Pause();
                btnPlayPause.Content = "Play";
            }

            void btnPlayPause_Unchecked(object sender, RoutedEventArgs e)
            {
                VideoElement.Play();
                btnPlayPause.Content = "Pause";
            }

        }
    }

    Friday, April 18, 2008 10:07 AM

Answers

  • Hello, where do you put the video file? It should be put in the ClientBin folder of the web project. When you create a new Silverlight project, make sure to choose also to create a web project. Then please run the web project to see if you can see the video.

    Monday, April 21, 2008 4:12 AM