Display Play Progress Bar Silverlight 2
Last post 05-05-2008 1:28 AM by Allen Chen – MSFT. 1 replies.
Sort Posts:
05-01-2008 6:50 PM
Display Play Progress Bar Silverlight 2

Hi

Can anyone look at the following page http://msdn.microsoft.com/en-us/library/cc189021(vs.95).aspx and work out how to use the code supplied to display a progress bar when the video is playing, i'll be reformating the xaml page once i get this to work

Thanks

George

 My Code is below

-----------------------------------------

using 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.Interop;

using System.Windows.Browser;

using System.Net;

using System.Windows.Resources;

using System.Windows.Media.Imaging;

using System.IO;

namespace Forum

{

public partial class Page : UserControl

{

public Page()

{

InitializeComponent();

FullScreenMode.MouseLeftButtonDown +=
new MouseButtonEventHandler(FullScreenMode_MouseLeftButtonDown);

App.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);

//this.PlayMedia.

PlayMedia.Source = new Uri("http://localhost:1969/Forum_Web/MemberMedia/WinVideo-YetAnotherCarousel.wmv", UriKind.RelativeOrAbsolute);PlayMediaFS.Source = new Uri("http://localhost:1969/Forum_Web/MemberMedia/WinVideo-YetAnotherCarousel.wmv", UriKind.RelativeOrAbsolute);

}

void FullScreenMode_MouseLeftButtonDown(object sender, MouseEventArgs e)

{

App.Current.Host.Content.IsFullScreen = App.Current.Host.Content.IsFullScreen ? false : true;

}

void Content_FullScreenChanged(object sender, EventArgs e)

{

if (App.Current.Host.Content.IsFullScreen)

{

double targetWidth = (double)App.Current.Host.Content.ActualWidth;

double targetHeight = (double)App.Current.Host.Content.ActualHeight;

Width = targetWidth;

Height = targetHeight;

PlayMediaFS.Width = targetWidth;

PlayMediaFS.Height = targetHeight;

PlayMediaFS.Visibility =
Visibility.Visible;

PlayMedia.Visibility = Visibility.Collapsed;

MediaCase.Visibility = Visibility.Collapsed;

MediaBackground.Visibility = Visibility.Collapsed;

//ButtonGroup.Visibility = Visibility.Collapsed;

mediaStateTextBlock.Visibility = Visibility.Collapsed;

}

else

{

PlayMediaFS.Visibility =
Visibility.Collapsed;

PlayMedia.Visibility = Visibility.Visible;

MediaCase.Visibility = Visibility.Visible;

MediaBackground.Visibility = Visibility.Visible;

//ButtonGroup.Visibility = Visibility.Visible;

mediaStateTextBlock.Visibility = Visibility.Visible;

 

}

}

void DownloadImagePart(string imgPart)

{

WebClient wc = new WebClient();

wc.OpenReadCompleted += new OpenReadCompletedEventHandler(wc_OpenReadCompleted);

wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);wc.OpenReadAsync(new Uri("http://localhost:1969/Forum_Web/MemberMedia/WinVideo-YetAnotherCarousel.wmv", UriKind.Relative), imgPart);

}

void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

{

// Calculate the downloaded percentage.

// Update the Rectangle and TextBlock objects of the visual progress indicator.

progressText.Text = e.ProgressPercentage.ToString();

progressRectangle.Width = (
double)e.ProgressPercentage;

}

public void Media_Play(object sender, MouseButtonEventArgs e)

{

PlayMedia.Play();

}

public void Media_Stop(object sender, MouseButtonEventArgs e)

{

PlayMedia.Stop();

}

public void Media_Pause(object sender, MouseButtonEventArgs e)

{

PlayMedia.Pause();

}

 

public void Media_State_Changed(object sender, EventArgs e)

{

mediaStateTextBlock.Text =
" Video: " + " " + PlayMedia.CurrentState.ToString();

}

 

}

}

 

---------------------------------------

 

<UserControl x:Class="Forum.Page"

xmlns="http://schemas.microsoft.com/client/2007"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="324" Height="308"

x:Name="RealEstate">

<Canvas x:Name="LayoutRoot" Background="White">

<MediaElement x:Name="PlayMediaFS"

Width="298"

Height="223"

AutoPlay="True"

Stretch="Fill">

</MediaElement>

<Rectangle x:Name="MediaBackground"

Canvas.Left="0"

Canvas.Top="0"

Width="324"

Height="308"

Fill="#E6E6E6"

Stroke="#C0C0C0"

StrokeThickness="3"

RadiusX="5"

RadiusY="5">

</Rectangle>

<Canvas x:Name="MediaCase"

Canvas.Left="14"

Canvas.Top="11"

Width="298"

Background="Black"

Height="223">

 

<MediaElement x:Name="PlayMedia"

Width="298"

Height="223"

AutoPlay="False"

CurrentStateChanged="Media_State_Changed"

 

Stretch="Fill">

</MediaElement>

</Canvas>

<!--<StackPanel Height="48.439"

Width="300"

Canvas.Left="10"

Canvas.Top="240"

x:Name="ButtonGroup"

Orientation="Horizontal">

-->

<Rectangle

Name="progressRectangle"

Canvas.Left="20"

Height="10" Width="0"

Fill="Maroon" />

 

<Rectangle

Canvas.Top ="-1"

Canvas.Left="19" Height="12"

Width="202"

StrokeThickness="1" Stroke="Black" />

<TextBlock

x:Name="progressText"

Canvas.Top ="-4" Canvas.Left="230"

Text="0%" FontSize="12" />

<!-- Play media. -->

<Button x:Name="mPlay"

MouseLeftButtonDown="Media_Play"

Canvas.Left="10"

Canvas.Top="240"

Width="50"

Height="30"

Content="Play"

Cursor="Hand"

ToolTip="Play"

FontSize="13"

/>

<!-- Pauses media playback. -->

<Button x:Name="mPause"

MouseLeftButtonDown="Media_Pause"

Canvas.Left="70"

Canvas.Top="240"

Width="50"

Height="30"

Content="Pause"

Cursor="Hand"

ToolTip="Pause"

FontSize="13"

/>

<!-- Stops media playback.-->

<Button x:Name="mStop"

MouseLeftButtonDown="Media_Stop"

Canvas.Left="130"

Canvas.Top="240"

Width="50"

Height="30"

Content="Stop"

Cursor="Hand"

ToolTip="Stop"

FontSize="13"

/>

<!--Full Screen-->

<Button x:Name="FullScreenMode"

Canvas.Left="190"

Canvas.Top="240"

Width="80"

Height="30"

Content="Full Screen"

Cursor="Hand"

ToolTip="Full Screen"

FontSize="13"

/>

<!-- </StackPanel>-->

<!-- Play media. -->

<!-- Pauses media playback. -->

<!-- Stops media playback.-->

 

<!--Full Screen-->

<TextBlock x:Name="mediaStateTextBlock"

Canvas.Top="280"

Canvas.Left="10"

FontSize="12"/>

</Canvas>

 

</UserControl>

gwphillipson

Joined on 04-25-2008
Posts 19
05-05-2008 1:28 AM
Marked as Answer
Re: Display Play Progress Bar Silverlight 2

Hello:

  I've replied in your another post.

http://silverlight.net/forums/p/15348/51115.aspx#51115

  Please don't cross post.

Thanks

Sincerely,
Allen Chen
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Allen Chen – MSFT

Joined on 03-16-2007
Posts 717