Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / WPF

Music Video Box (WPF)

Rate me:
Please Sign up or sign in to vote.
4.00/5 (4 votes)
10 Aug 2009CPOL3 min read 39.2K   1.8K   24  
This article explains the creation of a Music Video Box using Windows Presentation Foundation 3D Geometry and Media classes to play music albums as chosen by the user.
<Window x:Class="MusicVideoBox.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Music Video Box (WPF)" Width="1024"   Height="575" Left="50" Top="50">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="210"/>
            <ColumnDefinition Width="792*"/>
        </Grid.ColumnDefinitions>
        <Label Foreground="Yellow" FontSize="14" FontWeight="Bold" Background="Black" ClipToBounds="False" BorderBrush="AliceBlue" BorderThickness="2" Height="31" VerticalAlignment="Top">Select the Album here:</Label>
        <ListBox Name="listboxAlbum" Margin="2,31,0,0" Background="Black" SelectionChanged="ListBox_SelectionChanged">
            <ListBoxItem Foreground="Cyan" Content="None" />
            <ListBoxItem Foreground="Cyan" Content="Hindu-Devotional" />
            <ListBoxItem Foreground="Cyan" Content="Pop/Rock" />
            <ListBoxItem Foreground="Cyan" Content="Indian/Taare Zameen Par" />
        </ListBox>
        <DockPanel Grid.Column="1" Grid.Row="0"  Background="Black" Focusable="True" MouseLeftButtonDown="ChooseTrack">
            <Label Background="Black" BorderBrush="AliceBlue" BorderThickness="2" ClipToBounds="False" FontSize="14" FontWeight="Bold" Foreground="Yellow" Height="31" Width="789" IsHitTestVisible="False" Margin="0" DockPanel.Dock="Top">Click a picture to choose the track you want to play!</Label>
            <Viewport3D  ClipToBounds="True" Width="600" Height="400" Name="myViewport" Focusable="True" >
                <Viewport3D.Camera>
                    <PerspectiveCamera x:Name="myPerspectiveCamera"
            FarPlaneDistance="15" LookDirection="0,0,1" UpDirection="0,1,0" NearPlaneDistance="1" Position="0,0,-3" FieldOfView="50" />
                </Viewport3D.Camera>

                <ModelVisual3D x:Name="topModelVisual3D">
                    <ModelVisual3D.Children>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <AmbientLight Color="#333333" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>

                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <DirectionalLight Color="#FFFFFF" Direction="-0.612372,-0.5,-0.612372" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D>
                            <ModelVisual3D.Content>
                                <DirectionalLight Color="#FFFFFF" Direction="0.612372,-0.5,-0.612372" />
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side1ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side1GeometryModel3D" Geometry="{StaticResource CubeSide01}" Material="{StaticResource InitMaterial1}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side2ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side2GeometryModel3D" Geometry="{StaticResource CubeSide02}" Material="{StaticResource InitMaterial2}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side3ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side3GeometryModel3D" Geometry="{StaticResource CubeSide03}" Material="{StaticResource InitMaterial3}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side4ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side4GeometryModel3D" Geometry="{StaticResource CubeSide04}" Material="{StaticResource InitMaterial4}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side5ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side5GeometryModel3D"  Geometry="{StaticResource CubeSide05}" Material="{StaticResource InitMaterial5}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                        <ModelVisual3D x:Name="side6ModelVisual">
                            <ModelVisual3D.Content>
                                <GeometryModel3D x:Name="side6GeometryModel3D" Geometry="{StaticResource CubeSide06}" Material="{StaticResource InitMaterial6}" BackMaterial="{StaticResource InsideMaterial}"/>
                            </ModelVisual3D.Content>
                        </ModelVisual3D>
                    </ModelVisual3D.Children>
                    <ModelVisual3D.Transform>
                        <Transform3DGroup  >
                            <Transform3DGroup.Children>
                                <RotateTransform3D x:Name="myHorizontalRTransform">
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="myHorizontalRotation" Angle="0" Axis="0 1 0" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <RotateTransform3D x:Name="myVerticalRTransform">
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D x:Name="myVerticalRotation"  Angle="0" Axis="1 0 0" />
                                    </RotateTransform3D.Rotation>
                                </RotateTransform3D>
                                <TranslateTransform3D x:Name="myTranslateTransform" OffsetX="0" OffsetY="0" OffsetZ="0" />
                            </Transform3DGroup.Children >
                        </Transform3DGroup>
                    </ModelVisual3D.Transform>
                </ModelVisual3D>
                <Viewport3D.Triggers>
                    <EventTrigger RoutedEvent="Viewport3D.Loaded">
                        <BeginStoryboard>
                            <Storyboard x:Name="rotationStoryboard">
                                <DoubleAnimation 
                  Storyboard.TargetName="myVerticalRotation"
                  Storyboard.TargetProperty="Angle"
                  From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever"
                    />
                                <DoubleAnimation 
                  Storyboard.TargetName="myHorizontalRotation"
                  Storyboard.TargetProperty="Angle"
                  From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever"
                   />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </Viewport3D.Triggers>
            </Viewport3D>
        </DockPanel>
    </Grid>
</Window>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Founder BB Systems CIT-GPNP
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions