Friday, 2 April 2010

播放器 musicplayer in silverlight

網上看了幾看文獻所寫的一個播放器,事先聲明很垃圾的.我純粹試試mediaelement而已.








Get Microsoft Silverlight



mainpage.xaml



  1. <UserControl x:Class="musicPlayer.MainPage"

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

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

  4.    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

  5.    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">

  6.     <Grid x:Name="LayoutRoot" ShowGridLines="True" Background="Black">

  7.         <MediaElement x:Name="media" Source="HUMAN_TOUCH.mp3" AutoPlay="False"/>

  8.  

  9.         <StackPanel VerticalAlignment="Stretch">

  10.             <Button Content="Play" x:Name="play" Click="play_Click" Margin="5" />

  11.             <Button Content="Pause" x:Name="pause" Click="pause_Click" Margin="5" />

  12.             <Button Content="Stop" x:Name="stop" Click="stop_Click" Margin="5" />

  13.             <Button Content="Mute" x:Name="mute" Click="mute_Click" Margin="5" />

  14.             <Slider Grid.Row="1" x:Name="vol" Minimum="0" Maximum="1" ValueChanged="vol_ValueChanged" Margin="5" />

  15.         </StackPanel>        

  16.     </Grid>

  17. </UserControl>



mainpage.xaml.cs



  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Net;

  5. using System.Windows;

  6. using System.Windows.Controls;

  7. using System.Windows.Documents;

  8. using System.Windows.Input;

  9. using System.Windows.Media;

  10. using System.Windows.Media.Animation;

  11. using System.Windows.Shapes;

  12.  

  13. namespace musicPlayer

  14. {

  15.     public partial class MainPage : UserControl

  16.     {

  17.         public MainPage()

  18.         {

  19.             InitializeComponent();

  20.             vol.Value = media.Volume;

  21.         }  

  22.    

  23.  

  24.         private void play_Click(object sender, RoutedEventArgs e)

  25.         {            

  26.             media.Play();

  27.         }

  28.  

  29.         private void vol_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)

  30.         {

  31.             media.Volume = vol.Value;

  32.         }

  33.  

  34.         private void pause_Click(object sender, RoutedEventArgs e)

  35.         {

  36.             if (media.CanPause)

  37.                 media.Pause();

  38.         }

  39.  

  40.         private void stop_Click(object sender, RoutedEventArgs e)

  41.         {

  42.             media.Stop();

  43.         }

  44.  

  45.         private void mute_Click(object sender, RoutedEventArgs e)

  46.         {

  47.             if (media.IsMuted == true)

  48.             {

  49.                 media.IsMuted = false;

  50.             }

  51.             else

  52.             {

  53.                 media.IsMuted = true;

  54.             }

  55.         }

  56.     }

  57. }

0 comments:

Post a Comment