Wei-Meng Lee - C# 2008 Programmer's Reference

Здесь есть возможность читать онлайн «Wei-Meng Lee - C# 2008 Programmer's Reference» весь текст электронной книги совершенно бесплатно (целиком полную версию без сокращений). В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Город: Indianapolis, Год выпуска: 2009, ISBN: 2009, Издательство: Wiley Publishing, Inc., Жанр: Программирование, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

C# 2008 Programmer's Reference: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «C# 2008 Programmer's Reference»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

C# 2008 Programmers Reference provides a concise and thorough reference on all aspects of the language. Each chapter contains detailed code samples that provide a quick and easy way to understand the key concepts covered.

C# 2008 Programmer's Reference — читать онлайн бесплатно полную книгу (весь текст) целиком

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «C# 2008 Programmer's Reference», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Press F5 to test the page. Both videos start to play when the mouse hovers over either of the two videos (see Figure 19-56).

Figure 1956 Creating Your Own Media Player The MediaElementelement is a - фото 426

Figure 19-56

Creating Your Own Media Player

The MediaElementelement is a bare-bones control that simply plays back a media file — it does not have visual controls for you to pause or advance the media (although you can programmatically do that). In this section, you build a Silverlight application that resembles the YouTube player, allowing you to visually control the playback of the media as well as customize its look and feel. Figure 19-57 shows the end product.

Figure 1957 Creating the Project Using Expression Blend 2 create a new - фото 427

Figure 19-57

Creating the Project

Using Expression Blend 2, create a new Silverlight project and name it MediaPlayer.

Add a Windows Media file ( .wmv) file to the project by right-clicking on the project name and selecting Add Existing Item. For this project, use the same file as in the previous example, WindowsMedia.wmv.

Designing the User Interface

The first step is to design the user interface of the media player. Figure 19-58 shows the various controls that you will add to the page. The outline is used to identify the major parts of the player.

Figure 1958 Figure 1959 shows the organization and hierarchy of the various - фото 428

Figure 19-58

Figure 19-59 shows the organization and hierarchy of the various controls. Those controls correspond to the controls listed in Figure 19-58.

Figure 1959 The most delicate part of the media player is the slider used to - фото 429

Figure 19-59

The most delicate part of the media player is the slider used to indicate the progress of the media playback. As shown in Figure 19-60, the slider ( canvasProgress) consists of two Rectangleelements and an Ellipseelement. The first Rectangle element ( rectProgressWell) represents the entire duration of the movie. This control also forms the path that the marker (ellMarker, an Ellipse element) slides on. The second Rectanglecontrol ( rectDownloadProgress) is used to indicate the percentage of the media downloaded from the remote server. The lower part of Figure 19-60 shows this control in action (partially filled).

Figure 1960 Heres the complete XAML code for the media player - фото 430

Figure 19-60

Here's the complete XAML code for the media player:



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

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Width="472" Height="376"

Background="#FFD6D4C8" x:Name="Page">

x:Name="MediaElement1"

Width="466" Height="340"

Stretch="Fill"

Canvas.Left="3" Canvas.Top="3"

AutoPlay="false" Source="WindowsMedia.wmv"/>



Width="24" Height="24"

Canvas.Left="5" Canvas.Top="348"

x:Name="btnPlayPause">



Width="24" Height="24"

x:Name="canvasPlay">

Width="24" Height="24" Fill="#FFFFFFFF"

Stroke="#FF000000"

RadiusX="3" RadiusY="3"

x:Name="RectPlay" StrokeThickness="2"/>

Points="8,5 8,19 18,13"

StrokeThickness="5" Fill="Red"

Width="24" Height="24"/>



Width="24" Height="24"

x:Name="canvasPause"

MouseEnter="PauseButtonMouseEnter"

MouseLeave="PauseButtonMouseLeave"

Opacity="0">

Width="24" Height="24"

Fill="#FFFFFFFF"

Stroke="#FF000000"

RadiusX="3" RadiusY="3"

x:Name="RectPause" StrokeThickness="2"/>

Width="6" Height="14"

Fill="#FF141414"

Stroke="#FF000000"

Canvas.Left="13" Canvas.Top="5"

x:Name="rectPauseBar1"/>

Width="6" Height="14"

Fill="#FF141414"

Stroke="#FF000000"

Canvas.Left="5" Canvas.Top="5"

x:Name="rectPauseBar2"/>



Width="255" Height="27"

Canvas.Left="36" Canvas.Top="346"

x:Name="canvasProgress">

Width="244" Height="8"

Fill="#FF414141" Stroke="#FF000000"

Canvas.Top="10"

x:Name="rectProgressWell"

Canvas.Left="8.5"/>

Width="3" Height="8"

Fill="#FF9D0808" Stroke="#FF000000"

Canvas.Top="10"

x:Name="rectDownloadProgress"

StrokeThickness="0" Canvas.Left="8.5"/>

Width="16" Height="16"

Stroke="#FF000000"

Canvas.Top="6" Canvas.Left="0"

x:Name="ellMarker">

Width="148" Height="21"

Text="TextBlock" TextWrapping="Wrap"

Canvas.Left="321" Canvas.Top="348"

x:Name="TextBlock"/>

Wiring All the Controls

With the UI created and ready for coding, you're ready to wire up all the controls so that they will function as one. You'll define the event handlers in the following table.

Event Handler Description
DownloadProgressChanged() Continuously invoked when the MediaElementcontrol downloads the media from the remote server. It is used to update the red progress bar indicating the progress of the download.
EllMarkerMouseDown() Invoked when the user clicks on the marker using the left mouse button.
EllMarkerMouseUp() Invoked when the user releases the left mouse button.
MediaPlayerMouseMove() Invoked when the mouse moves across the Silverlight page.
MediaPlayerMouseLeave() Invoked when the mouse leaves the Silverlight page.
MediaEnded() Invoked when the media has finished playing. The media will be reset to its starting position (so is the marker).
PlayPauseButtonUp() Invoked when the user clicks on the Play/Pause button.

First, assign the various event handlers to the elements as shown in the following highlighted code:



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

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Width="472" Height="376"

Background="#FFD6D4C8"

x:Name="Page"

MouseMove="MediaPlayerMouseMove"

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «C# 2008 Programmer's Reference»

Представляем Вашему вниманию похожие книги на «C# 2008 Programmer's Reference» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «C# 2008 Programmer's Reference»

Обсуждение, отзывы о книге «C# 2008 Programmer's Reference» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x