Click here to Skip to main content
15,885,914 members
Articles / Desktop Programming / WPF

A simple WPF media player with media item list

Rate me:
Please Sign up or sign in to vote.
4.89/5 (58 votes)
13 Sep 2007CPOL4 min read 406.6K   20.1K   140  
A simple WPF media player with media item list.
<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="WPF_Media_Player.ucMediaPlayer"
    Loaded="ucMediaPlayer_Loaded"
>

  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Resources/Styles.xaml"/>
        <ResourceDictionary Source="Resources/Templates.xaml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </UserControl.Resources>  
  
  
 

  

  <Grid x:Name ="grdMain" Background="White">



    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="150" x:Name="col0" />
      <ColumnDefinition Width="*" x:Name="col1" />
    </Grid.ColumnDefinitions>

    <Grid.RowDefinitions>
      <RowDefinition Height="*" x:Name="row1" />
      <RowDefinition Height="60" x:Name="row2" />
    </Grid.RowDefinitions>




    <ScrollViewer x:Name="svMediaItems" Grid.Row="0" Grid.Column="0" HorizontalScrollBarVisibility="Disabled" Width="150" Drop="Media_Drop" AllowDrop="True" BorderThickness="0,0,0,0" BorderBrush="Transparent" Margin="0,0,0,50">
      <StackPanel Orientation="Vertical"   Background="White" >

       
        <Label Background="White" Foreground="Gray" FontFamily="Tahoma" FontSize="10" BorderBrush="Transparent" Content="Drag Media Items Here..."/>
        <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
          <Label x:Name="lblSave" MouseDown="lblSave_MouseDown" RenderTransformOrigin="0.5,0.5" Background="Transparent" Foreground="Gray" FontFamily="Wingdings" FontSize="14" BorderBrush="Transparent" Content="=" ToolTip="Save" Style="{DynamicResource PulseLabel}"/>
          <Label x:Name="lblLoad" MouseDown="lblLoad_MouseDown" RenderTransformOrigin="0.5,0.5" Background="Transparent" Foreground="Gray" FontFamily="Wingdings" FontSize="14" BorderBrush="Transparent" Content="6" ToolTip="Load" Style="{DynamicResource PulseLabel}"/>
          <Label x:Name="lblClear" MouseDown="lblClear_MouseDown"   RenderTransformOrigin="0.5,0.5" Background="Transparent" Foreground="Gray" FontFamily="Wingdings" FontSize="14" BorderBrush="Transparent" Content="û" ToolTip="Clear" Style="{DynamicResource PulseLabel}"/>
          <Label x:Name="lbl3D" MouseDown="lbl3D_MouseDown" RenderTransformOrigin="0.5,0.5" Background="Transparent" Foreground="Gray" FontFamily="Wingdings" FontSize="14" BorderBrush="Transparent" Content="r" ToolTip="Use 3D Style Media Items" Style="{DynamicResource PulseLabel}"/>
          <Label x:Name="lblNormal" MouseDown="lblNormal_MouseDown" RenderTransformOrigin="0.5,0.5" Background="Transparent" Foreground="Gray" FontFamily="Wingdings" FontSize="14" BorderBrush="Transparent" Content="o" ToolTip="Use Flat Style Media Items" Style="{DynamicResource PulseLabel}"/>
        </StackPanel>
        <ListBox x:Name="lstMediaItems" 
                  SelectionChanged="lstMediaItems_SelectionChanged"  
                  BorderBrush="White"  
                  Background="White" Width="150"   
                  ScrollViewer.HorizontalScrollBarVisibility ="Disabled">
          <ListBox.ItemTemplate>
            <DataTemplate>
              <Button x:Name="lstMediaItemBtn" VerticalAlignment="Center" Style="{DynamicResource ButtonStyle}"  Click="btnMediaItems_Clicked">
                <Button.ToolTip>
                  <StackPanel Orientation="Vertical">
                    <Label Background="Black" Margin="2,2,2,2" FontWeight="Bold" FontFamily="Arial" Foreground="White" Content="{Binding Path=ItemUri}"/>
                    <TextBlock Padding="10" TextWrapping="WrapWithOverFlow" Width="200">
                      You have rated this media item with a rating of
                    </TextBlock>
                    <Label Padding="10"  FontFamily="Arial" FontSize="20" FontWeight="Bold" Content="{Binding Path=ItemRatingFull}"/>
                  </StackPanel>
                </Button.ToolTip>
                <MediaElement Name="lstMediaItem" Source="{Binding Path=ItemUri}" LoadedBehavior="Play"  Volume="0" />
              </Button>
            </DataTemplate>
          </ListBox.ItemTemplate>
          
          <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
              <WrapPanel/>
            </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
        </ListBox>
      </StackPanel>
    </ScrollViewer>



    <Border x:Name="mediaPlayerBorder" Background="Gray" BorderBrush="Gray" Grid.Row="0" Grid.Column="1" BorderThickness="4,4,4,4" Margin="2,2,5,2" CornerRadius="5,5,5,5" ToolTip="Click here to collapse/expand the video">
      <Button  x:Name="btnMediaPlayerMain" Click="btnMediaPlayerMain_Click"  Height="Auto" Width="Auto" Template="{StaticResource transparentButtonTemplate}">
      <MediaElement    x:Name="mediaPlayerMain" MediaOpened="mediaPlayerMain_MediaOpened" MediaEnded="mediaPlayerMain_MediaEnded"  LoadedBehavior="Manual"   Margin="0,0,0,0" Stretch="Fill"/>
    </Button>
    </Border>

    <Border Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="5,5,5,5" Background="WhiteSmoke" BorderBrush="Gray" BorderThickness="4,4,4,4" Margin="10,5,5,10">
      <StackPanel Background="Transparent" Width="Auto" Margin="0,0,0,0" Orientation="Horizontal" Height="Auto">
        <Button x:Name="btnPlay" Click="btnPlay_Click" Width="50" Height="50" Margin="10,-30,0,0" Template="{StaticResource controlButtonTemplate}" FontSize="14" FontWeight="Bold" Foreground="LightGreen" Content="4" FontFamily="Webdings" ToolTip="Play"></Button>
        <Button x:Name="btnPause" Click="btnPause_Click"  Width="40" Height="40" Margin="-15,-50,0,0" Template="{StaticResource controlButtonTemplate}" FontSize="14" FontWeight="Bold" Foreground="Orange" Content=";" FontFamily="Webdings" ToolTip="Pause"></Button>
        <Button x:Name="btnStop" Click="btnStop_Click"  Width="30" Height="30" Margin="-10,-45,0,0" Template="{StaticResource controlButtonTemplate}" FontSize="14" FontWeight="Bold" Foreground="Yellow" Content="&lt;" FontFamily="Webdings" ToolTip="Stop"></Button>
        <!-- Seek Control -->
        <TextBlock Foreground="Gray" Margin="-10,5,5,5"  VerticalAlignment="Center" FontSize="10">Seek To</TextBlock>
        <Slider Name="sliderTime" Margin="2,0,0,0" VerticalAlignment="Center" ValueChanged="SeekToMediaPosition" Width="80" Height="Auto" />
        <!-- Volume Control -->
        <TextBlock Foreground="Gray" Margin="5,5,5,5"  VerticalAlignment="Center" FontSize="10">Volume</TextBlock>
        <Slider Name="sliderVolume" Margin="2,0,0,0" VerticalAlignment="Center" ValueChanged="ChangeMediaVolume" Width="80" Height="Auto" Minimum="0" Maximum="1" Value="0.5"/>

        <StackPanel Orientation="Vertical" Margin="10,0,0,0">
          <TextBlock x:Name="txtRating" Foreground="Gray" Margin="0,0,0,0"  VerticalAlignment="Center" FontSize="10">Rating For Item</TextBlock>
          <StackPanel x:Name="starStack" Orientation="Horizontal">
          </StackPanel>
        </StackPanel>
      </StackPanel>
    </Border>




  </Grid>
</UserControl>

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
Software Developer (Senior)
United Kingdom United Kingdom
I currently hold the following qualifications (amongst others, I also studied Music Technology and Electronics, for my sins)

- MSc (Passed with distinctions), in Information Technology for E-Commerce
- BSc Hons (1st class) in Computer Science & Artificial Intelligence

Both of these at Sussex University UK.

Award(s)

I am lucky enough to have won a few awards for Zany Crazy code articles over the years

  • Microsoft C# MVP 2016
  • Codeproject MVP 2016
  • Microsoft C# MVP 2015
  • Codeproject MVP 2015
  • Microsoft C# MVP 2014
  • Codeproject MVP 2014
  • Microsoft C# MVP 2013
  • Codeproject MVP 2013
  • Microsoft C# MVP 2012
  • Codeproject MVP 2012
  • Microsoft C# MVP 2011
  • Codeproject MVP 2011
  • Microsoft C# MVP 2010
  • Codeproject MVP 2010
  • Microsoft C# MVP 2009
  • Codeproject MVP 2009
  • Microsoft C# MVP 2008
  • Codeproject MVP 2008
  • And numerous codeproject awards which you can see over at my blog

Comments and Discussions