wpf和wp7版网络音乐播放器,使用虾米网的资源

软件介绍:本软件使用虾米网的资源,真正下载虾米网的音乐要用积分,所以在这不添加下载功能。代码也只贴部分。我用的NetFramework4.0 不知道在别的电脑上能不能支持。

api是怎么得到的,就是下载它的swf文件,然后反编译,分析代码找到xml地址,MP3地址是加密的,解密算法也是在swf文件里,有兴趣的同学可以研究一下。还有个budge ,mediaElement不在咋了,pause不好使,就是停不下,所以改成了静音效果,伪装成暂停。

下载地址(非源码):https://files.cnblogs.com/wxdtk1989/SkyMusic.zip  不足之处请谅解。

图:

部分代码:

xaml:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:ec="http://schemas.microsoft.com/expression/2010/controls" 
        xmlns:SkyMuisc_Properties="clr-namespace:SkyMuisc.Properties"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
        xmlns:System="clr-namespace:System;assembly=mscorlib" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        x:Class="SkyMuisc.MainWindow"
        Title="天空的声音" Height="550" Width="280" WindowStartupLocation="CenterScreen" MaxWidth="280" MaxHeight="550" WindowStyle="SingleBorderWindow" MinWidth="280" MinHeight="550" FontSize="16" Icon="/SkyMuisc;component/20100829224935145.ico" Loaded="Window_Loaded" MouseDown="Window_MouseDown">
    <Window.ContextMenu>
        <ContextMenu  Name="contextmenu1">
            <MenuItem Header="关于我" Name="MenuItem1" Click="MenuItem1_Click" />
            <MenuItem Header="退出" Name="MenuItem2" Click="MenuItem2_Click"/>
        </ContextMenu>
    </Window.ContextMenu>
    <Window.Resources>
        <Style x:Key="ButtonStyle1" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.CustomVisualStateManager>
                                <ei:ExtendedVisualStateManager/>
                            </VisualStateManager.CustomVisualStateManager>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates" ei:ExtendedVisualStateManager.UseFluidLayout="True">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ellipse">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.56"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="ellipse" Stroke="Black" StrokeThickness="3">
                                <Ellipse.Fill>
                                    <ImageBrush ImageSource="appbar.transport.play.rest.png"/>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True"/>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ButtonStyle2" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.CustomVisualStateManager>
                                <ei:ExtendedVisualStateManager/>
                            </VisualStateManager.CustomVisualStateManager>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates" ei:ExtendedVisualStateManager.UseFluidLayout="True">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ellipse">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.56"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="ellipse" Stroke="Black" StrokeThickness="3">
                                <Ellipse.Fill>
                                    <ImageBrush ImageSource="appbar.transport.pause.rest.png"/>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True"/>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ButtonStyle3" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.CustomVisualStateManager>
                                <ei:ExtendedVisualStateManager/>
                            </VisualStateManager.CustomVisualStateManager>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates" ei:ExtendedVisualStateManager.UseFluidLayout="True">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ellipse">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.56"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="ellipse" Stroke="Black" StrokeThickness="3">
                                <Ellipse.Fill>
                                    <ImageBrush ImageSource="appbar.transport.ff.rest.png"/>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True"/>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ButtonStyle4" TargetType="{x:Type Button}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <VisualStateManager.CustomVisualStateManager>
                                <ei:ExtendedVisualStateManager/>
                            </VisualStateManager.CustomVisualStateManager>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates" ei:ExtendedVisualStateManager.UseFluidLayout="True">
                                    <VisualState x:Name="Normal"/>
                                    <VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ellipse">
                                                <EasingDoubleKeyFrame KeyTime="0" Value="0.56"/>
                                            </DoubleAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="ellipse">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <System:Double>35</System:Double>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled"/>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="ellipse" Stroke="Black" StrokeThickness="3">
                                <Ellipse.Fill>
                                    <ImageBrush ImageSource="appbar.download.rest.png"/>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Content=""/>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsFocused" Value="True"/>
                            <Trigger Property="IsDefaulted" Value="True"/>
                            <Trigger Property="IsMouseOver" Value="True"/>
                            <Trigger Property="IsPressed" Value="True"/>
                            <Trigger Property="IsEnabled" Value="False"/>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.RowDefinitions>
        	<RowDefinition Height="148*" />
        	<RowDefinition Height="200" />
        	<RowDefinition Height="30*" />
            <RowDefinition Height="133*" />
        </Grid.RowDefinitions>
        <Expander Height="58" HorizontalAlignment="Left" x:Name="expander1" VerticalAlignment="Top" Width="254" Header="频道选择" Margin="1,73,0,0" RenderTransformOrigin="0.5,0.5" Grid.Row="3">
        	<Expander.RenderTransform>
        		<TransformGroup>
        			<ScaleTransform/>
        			<SkewTransform/>
        			<RotateTransform/>
        			<TranslateTransform/>
        		</TransformGroup>
        	</Expander.RenderTransform>
            <WrapPanel Height="24" Name="wrapPanel1" Width="244" >
                <RadioButton Content="动漫" Height="26" Name="radioButton1" IsChecked="False" Checked="radioButton1_Checked" />
                <RadioButton Content="华语" Height="26" Name="radioButton2" Checked="radioButton2_Checked" />
                <RadioButton Content="欧美" Height="26" Name="radioButton3" Checked="radioButton3_Checked" />
                <RadioButton Content="日语" Height="26" Name="radioButton4" Checked="radioButton4_Checked" />
                <RadioButton Content="韩语" Height="26" Name="radioButton5" Checked="radioButton5_Checked" />
            </WrapPanel>
        </Expander>
        <Rectangle Height="15" HorizontalAlignment="Left" Margin="35,146,0,0" x:Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="185" StrokeThickness="0" Grid.RowSpan="2">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="1" />
                    <GradientStop Color="Transparent" Offset="0.099" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Height="185" HorizontalAlignment="Left" Margin="218,10,0,0" x:Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="15" StrokeThickness="0" Grid.Row="1">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="Transparent" Offset="0.814" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Height="20" HorizontalAlignment="Left" Margin="35,190,0,0" x:Name="rectangle4" Stroke="Black" VerticalAlignment="Top" Width="185" StrokeThickness="0" Grid.Row="1" Grid.RowSpan="2">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="Transparent" Offset="0.872" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle Height="185" HorizontalAlignment="Left" Margin="23,10,0,0" x:Name="rectangle3" Stroke="Black" VerticalAlignment="Top" Width="15" StrokeThickness="0" Grid.Row="1">
            <Rectangle.Fill>
                <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                    <GradientStop Color="Black" Offset="1" />
                    <GradientStop Color="Transparent" Offset="0.099" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Image Grid.Row="1" Height="185" HorizontalAlignment="Left" Margin="35,10,0,0" Name="image2" Stretch="UniformToFill" VerticalAlignment="Top" Width="185" Source="/SkyMuisc;component/Images/20100829224935145.png" />
        <Image Height="185" HorizontalAlignment="Left" Margin="35,10,0,0" x:Name="image1" Stretch="UniformToFill" VerticalAlignment="Top" Width="185" Source="{Binding ElementName=textBox1,Path=Text}" Grid.Row="1" ToolTip="专辑图片" />
        <Rectangle Height="28" HorizontalAlignment="Left" Margin="35,197,0,0" x:Name="rectangle5" Stroke="Black" VerticalAlignment="Top" Width="185" Stretch="UniformToFill" StrokeThickness="0" Grid.Row="1" Grid.RowSpan="2" >
            <Rectangle.Fill>
                <VisualBrush Visual="{Binding ElementName=image1}">
                    <VisualBrush.RelativeTransform >
                        <TransformGroup>
                            <ScaleTransform ScaleX="1" ScaleY="-1"/>
                            <TranslateTransform Y="1"/>
                        </TransformGroup>
                    </VisualBrush.RelativeTransform>
                </VisualBrush>
            </Rectangle.Fill>
            <Rectangle.OpacityMask>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="#2DFFFFFF" Offset="0.081" />
                </LinearGradientBrush>
            </Rectangle.OpacityMask>
        </Rectangle>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="31,31,0,0" x:Name="textBlock1" Text="歌曲:" VerticalAlignment="Top" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="31,69,0,0" x:Name="textBlock2" Text="演唱:" VerticalAlignment="Top" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="31,106,0,0" x:Name="textBlock3" Text="专辑:" VerticalAlignment="Top" />
        <TextBlock Height="40" HorizontalAlignment="Left" Margin="85,31,0,0" x:Name="textBlocksong" Text="无" VerticalAlignment="Top" Width="163" TextWrapping="Wrap" />
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="85,69,0,0" x:Name="textBlocksing" Text="无" VerticalAlignment="Top" Width="163" />
        <TextBlock Height="42" HorizontalAlignment="Left" Margin="85,106,0,0" x:Name="textBlockalbum" Text="无" VerticalAlignment="Top" Width="163" TextWrapping="Wrap" />
        <MediaElement Grid.Row="1" Height="42" HorizontalAlignment="Left" Margin="5,38,0,0" Name="mediaElementsong" VerticalAlignment="Top" Width="26" UnloadedBehavior="Manual" MediaEnded="mediaElementsong_MediaEnded" MediaFailed="mediaElementsong_MediaFailed" />
        <TextBox Grid.RowSpan="2" Height="243" HorizontalAlignment="Left" Margin="12,20,0,0" Name="textBox1" VerticalAlignment="Top" Width="246" TextWrapping="Wrap" FontSize="12" Visibility="Hidden" />
        <Button Content="Button" HorizontalAlignment="Left" Margin="69,0,0,66" Style="{DynamicResource ButtonStyle1}" Width="40" Height="40" VerticalAlignment="Bottom" Grid.Row="3" Name="buttonstart" Click="buttonstart_Click" ToolTip="播放" IsEnabled="False" />
        <Button Content="Button" HorizontalAlignment="Left" Margin="70,0,0,66" Style="{DynamicResource ButtonStyle2}" Width="40" Height="40" VerticalAlignment="Bottom" Grid.Row="3" Name="buttonpause" Visibility="Collapsed" Click="buttonpause_Click" ToolTip="暂停" />
        <Button Content="Button" HorizontalAlignment="Left" Margin="115,0,0,66" Style="{DynamicResource ButtonStyle3}" Width="40" Height="40" VerticalAlignment="Bottom" Grid.Row="3" Name="buttonnext" Click="buttonnext_Click" Visibility="Visible" IsEnabled="False" ToolTip="下一首" />
        <Button Content="Button" HorizontalAlignment="Left" Margin="161,0,0,66" Style="{DynamicResource ButtonStyle4}" Width="40" Height="40" VerticalAlignment="Bottom" Grid.Row="3" Name="buttondown" Click="buttondown_Click" ToolTip="下载到桌面" IsEnabled="False" />
        <CheckBox Content="玻璃效果" Height="22" HorizontalAlignment="Left" Margin="25,5,0,0" Name="checkBox1" VerticalAlignment="Top" IsChecked="True" Unchecked="checkBox1_Unchecked" Checked="checkBox1_Checked" />
        <TextBlock Height="31" HorizontalAlignment="Left" Margin="70,127,0,0" Name="textBlock4" Text="正在初始化......" VerticalAlignment="Top" Foreground="#FFEB1B1B" Grid.RowSpan="2" FontSize="18" />
        <ProgressBar Grid.Row="3" Height="10" HorizontalAlignment="Left" Margin="47,6,0,0" Name="progressBar1" VerticalAlignment="Top" Width="168" Panel.ZIndex="1" ToolTip="进度" IsEnabled="True" Background="#78DECACA">
            <ProgressBar.Foreground>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="#FF0A0705" Offset="1" />
                    <GradientStop Color="#FF56585C" Offset="0" />
                    <GradientStop Color="Black" Offset="0.459" />
                </LinearGradientBrush>
            </ProgressBar.Foreground>
        </ProgressBar>
        <TextBlock Grid.Row="3" Height="19" HorizontalAlignment="Left" Margin="219,2,0,0" Name="textBlock5" Text="00:00" VerticalAlignment="Top" FontSize="14" Width="37" />
        <TextBlock FontSize="14" Height="19" HorizontalAlignment="Left" Margin="7,2,0,0" Name="textBlock6" Text="00:00" VerticalAlignment="Top" Width="37" Grid.Row="3" />
        <Label Content="{x:Static System:Environment.UserName}" Height="38" HorizontalAlignment="Left" Margin="115,-1,0,0" Name="label1" VerticalAlignment="Top" Width="59" Visibility="Collapsed" />
        <Expander Header="定时关机" Height="100" HorizontalAlignment="Left" Margin="124,7,0,0" Name="expander2" VerticalAlignment="Top" Width="132" BorderThickness="3">
            <Grid>
                <TextBox Height="23" HorizontalAlignment="Left" Margin="8,6,0,0" Name="textBox2" VerticalAlignment="Top" Width="46" BorderThickness="2" BorderBrush="#E6000000" Background="#00000000" FontSize="14" HorizontalContentAlignment="Center" TextAlignment="Center" Text="" />
                <TextBlock Height="23" HorizontalAlignment="Left" Margin="59,6,0,0" Name="textBlock7" Text="分钟关机" VerticalAlignment="Top" Width="66" />
                <CheckBox Content="确定" Height="25" HorizontalAlignment="Left" Margin="37,36,0,0" Name="checkBox2" VerticalAlignment="Top" Width="56" Checked="checkBox2_Checked" Unchecked="checkBox2_Unchecked" />
            </Grid>
        </Expander>
    </Grid>
</Window>

  

  

C#:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using System.IO;
using System.Xml.Linq;
using System.Net;
using System.Windows.Threading;
namespace SkyMuisc
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public string albumurl;
        public string[] title1 = new string[80];//歌名
        public string[] album_name1 = new string[80];//专辑
        public string[] artist1 = new string[80];//歌手
        public string[] pic1 = new string[80];//图片
        public string[] location1 = new string[80];//地址
        public int x = 0,y=0,z=0,w=0;
        DispatcherTimer t = new DispatcherTimer();
        DispatcherTimer t1 = new DispatcherTimer();
        public MainWindow()
        {
            InitializeComponent();

        }
        [StructLayout(LayoutKind.Sequential)]
        public struct MARGINS
        {
            public int cxLeftWidth;
            public int cxRightWidth;
            public int cyTopHeight;
            public int cyBottomHeight;
        }
        #region  引用 Dll
        [DllImport("DwmApi.dll")]
        public static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS pMarInset);
        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);
        [DllImport("user32.dll", EntryPoint = "ReleaseCapture")]
        public static extern int ReleaseCapture();
        public const int WM_SysCommand = 0x0112;
        public const int SC_MOVE = 0xF012;
        [DllImport ("e_xitong.dll")]
        public static extern void  guanji();

        #endregion
        private void Window_Loaded(object sender, RoutedEventArgs e)
         {
             try
             {
                 StreamReader r = new StreamReader("stye.txt");
                 string radioche = r.ReadToEnd();
                 r.Close();
                 if (radioche=="动漫")
                 {
                     radioButton1.IsChecked = true;
                 }
                 if (radioche == "华语")
                 {
                     radioButton2.IsChecked = true;
                 }
                 if (radioche == "欧美")
                 {
                     radioButton3.IsChecked = true;
                 }
                 if (radioche == "日语")
                 {
                     radioButton4.IsChecked = true;
                 }
                 if (radioche == "韩语")
                 {
                     radioButton5.IsChecked = true;
                 }
             }
             catch (Exception)
             {
                 albumurl = albumid("动漫");
                 radioButton1.IsChecked = true;
             }
           // xmlMusic(albumurl);
            this.Background = Brushes.Transparent;
            ExtendAeroGlass(this);

        }
        private void ExtendAeroGlass(Window window)
        {
            try
            {
                // 为WPF程序获取窗口句柄
                IntPtr mainWindowPtr = new WindowInteropHelper(window).Handle;
                HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
                mainWindowSrc.CompositionTarget.BackgroundColor = Colors.Transparent;
                // 设置Margins
                MARGINS margins = new MARGINS();

                // 扩展Aero Glass
                margins.cxLeftWidth = -1;
                margins.cxRightWidth = -1;
                margins.cyTopHeight = -1;
                margins.cyBottomHeight = -1;

                int hr = DwmExtendFrameIntoClientArea(mainWindowSrc.Handle, ref margins);
                if (hr < 0)
                {
                    checkBox1.IsChecked = false;
                    MessageBox.Show("玻璃效果加载失败!");
                }
            }
            catch (DllNotFoundException)
            {
                Application.Current.MainWindow.Background = Brushes.White;
            }
        }
        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            IntPtr mainWindowPtr = new WindowInteropHelper(this).Handle;
            HwndSource mainWindowSrc = HwndSource.FromHwnd(mainWindowPtr);
            ReleaseCapture();
            SendMessage(mainWindowSrc.Handle.ToInt32(), WM_SysCommand, SC_MOVE, 0);
        }

        private void buttonstart_Click(object sender, RoutedEventArgs e)
        {
            w = 0;
            buttonnext.IsEnabled = true;
            buttonstart.Visibility = Visibility.Collapsed;
            buttonpause.Visibility = Visibility.Visible;
            textBlock4.Visibility = Visibility.Collapsed;
            if (z == 0)
            {
                information();
            }
            mediaElementsong.Volume = 1;
            t.Interval = new TimeSpan(0,0,1);
            t.Start();
            t.Tick += new EventHandler(t_Tick);
           // mediaElementsong.Play();
        }

        void t_Tick(object sender, EventArgs e)
        {
            try
            {
                textBlock5.Text = (mediaElementsong.NaturalDuration).ToString().Substring(3, 5);
                textBlock6.Text = (mediaElementsong.Position).ToString().Substring(3, 5);
                progressBar1.Value =(int)(((double.Parse(textBlock6.Text.Substring(0, 2)) * 60 + double.Parse(textBlock6.Text.Substring(3, 2)))
                    / (double.Parse(textBlock5.Text.Substring(0, 2)) * 60 + double.Parse(textBlock5.Text.Substring(3, 2)))) * 100);         
            }
            catch (Exception)
            {
            }
        }
        private void buttonpause_Click(object sender, RoutedEventArgs e)
        {
            w = 1;
            buttonstart.Visibility = Visibility.Visible;
            buttonpause.Visibility = Visibility.Collapsed;
            mediaElementsong.Volume = 0;  //假暂停
               //+mediaElementsong.NaturalDuration+'\n'
               //+mediaElementsong.Position+'\n';
            z = 1;
        }

        private void buttonnext_Click(object sender, RoutedEventArgs e)
        {
            buttonstart.Visibility = Visibility.Collapsed;
            buttonpause.Visibility = Visibility.Visible;
            w = 0;
            nextSong();
            progressBar1.Value = 0;
            t.Interval = new TimeSpan(0, 0, 1);
            t.Start();
            t.Tick += new EventHandler(t_Tick);
        }

        private void nextSong()
        {
            x++;
            try
            {
                if (x <= y)
                {
                    information();
                    textBlock4.Visibility = Visibility.Collapsed;
                }
                else
                {
                    textBlock4.Visibility = Visibility.Visible;
                    textBlock4.Text = "加载下一专辑中...";
                    x = 0;
                    xmlMusic(albumurl);
                    information();
                    textBlock4.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception)
            {

            }
        }

        private void information()
        {
            try
            {
                textBlocksing.Text = artist1[x];
                textBlocksong.Text = title1[x];
                textBlockalbum.Text = album_name1[x];
                textBox1.Text = pic1[x];
                mediaElementsong.Source = new Uri(location1[x]);
                mediaElementsong.Play();
                Binding bing = new Binding();
                bing.Source = textBox1;
                bing.Path = new PropertyPath("Text");
                image1.SetBinding(TextBox.TextProperty, bing);
            }
            catch (Exception)
            {

                MessageBox.Show("没有地址!!");
            }

        }

        private void buttondown_Click(object sender, RoutedEventArgs e)
        {
            try
            {
               //
            }
            catch (Exception)
            {
                MessageBox.Show("出什么问题了?下不了");
            }
        }
        private string albumid(string some)
        {
            string id = "";
            XDocument xdo = XDocument.Load("albumid/"+some+".xml");
            var album = (from query in xdo.Elements("album") 
                         select query).FirstOrDefault().Value.Split(']');
            Random rid = new Random();
            id=album[rid.Next(0, 200)];
            return id;
        }

        private void radioButton1_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                albumurl = albumid("动漫");
                xmlMusic(albumurl);
                x = 0;
                StreamWriter win = new StreamWriter("stye.txt");
                win.Write("动漫");
                win.Close();
            }
            catch (Exception)
            {

            }
            
        }

        private void radioButton2_Checked(object sender, RoutedEventArgs e)
        {
            albumurl = albumid("华语");
            xmlMusic(albumurl);
            x = 0;
            StreamWriter win = new StreamWriter("stye.txt");
            win.Write("华语");
            win.Close();
        }

        private void radioButton3_Checked(object sender, RoutedEventArgs e)
        {
            albumurl = albumid("欧美");
            xmlMusic(albumurl);
            x = 0;
            StreamWriter win = new StreamWriter("stye.txt");
            win.Write("欧美");
            win.Close();
        }

        private void radioButton4_Checked(object sender, RoutedEventArgs e)
        {
            albumurl = albumid("日语");
            xmlMusic(albumurl);
            x = 0;
            StreamWriter win = new StreamWriter("stye.txt");
            win.Write("日语");
            win.Close();
        }

        private void radioButton5_Checked(object sender, RoutedEventArgs e)
        {
            albumurl = albumid("韩语");
            xmlMusic(albumurl);
            x = 0;
            StreamWriter win = new StreamWriter("stye.txt");
            win.Write("韩语");
            win.Close();
        }
        private void xmlMusic(string some)
        {
            string httpurl = "http://www.xiami.com。。。。。。";
            WebClient webc = new WebClient();
            webc.OpenReadAsync(new Uri(httpurl + some + "/type/3"));
            webc.OpenReadCompleted += new OpenReadCompletedEventHandler(webc_OpenReadCompleted);
           
        }
        void webc_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            int a = 1, b = 1, c = 1, d = 1, e1 = 1, f = 1, g = 1, h = 1, j = 1, k = 1;
            string webxml;
            songApi songuri = new songApi();
            try
            {
                using (StreamReader read = new StreamReader(e.Result, Encoding.UTF8))
                {
                    webxml = read.ReadToEnd();
                }
                for (int i = 0; i < 60; i++)
                {
                    try
                    {      //读xml时出问题,我就改成字符串操作了,也挺好的
                        a = webxml.IndexOf("<title><![CDATA[", a + 16);
                        b = webxml.IndexOf("]]></title>", b + 11);
                        title1[i] = webxml.Substring(a + 16, b - a - 16);

                        c = webxml.IndexOf("<album_name><![CDATA[", c + 21);
                        d = webxml.IndexOf("]]></album_name>", d + 16);
                        album_name1[i] = webxml.Substring(c + 21, d - c - 21);

                        e1 = webxml.IndexOf("<artist>", e1 + 8);
                        f = webxml.IndexOf("</artist>", f + 9);
                        artist1[i] = webxml.Substring(e1 + 8, f - e1 - 8);

                        g = webxml.IndexOf("<location>", g + 10);
                        h = webxml.IndexOf("</location>", h + 11);
                        location1[i] = songuri.GetLocation(webxml.Substring(g + 10, h - g - 10));

                        j = webxml.IndexOf("<pic>", j + 5);
                        k = webxml.IndexOf("</pic>", k + 6);
                        string p = webxml.Substring(j + 5, k - j - 5);
                        pic1[i] = p.Replace("_1", "_2");
                        y = i;
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
                textBlock4.Text = "按播放键,播放";
                buttonstart.IsEnabled = true;
                buttondown.IsEnabled = true;
            }
              
            catch (Exception)
            {

               MessageBox.Show ("貌似网络不行~\\(≧▽≦)//~啦啦啦");
            }
        }
        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
            try
            {
                ImageBrush back = new ImageBrush();
                back.ImageSource = new BitmapImage(new Uri("Images/back.jpg", UriKind.Relative));
                this.Background = back;
            }
            catch (Exception)
            {
                MessageBox.Show("找不到图back.jpg!");
                this.Background = Brushes.SkyBlue;
            }


        }

        private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
            this.Background = Brushes.Transparent;
            
        }

        private void mediaElementsong_MediaEnded(object sender, RoutedEventArgs e)
        {
            if (w==0)
            {
                nextSong(); 
            }
            
        }

        private void mediaElementsong_MediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            textBlock4.Visibility = Visibility.Visible;
            textBlock4.Text = "歌曲加载失败!!";
        }
        private void MenuItem2_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void MenuItem1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("作者:无限的天空1989" + '\n' + "联系方式:gaozhao0331@163.com" + 
'\n' + "说明:本软件音乐资源使用《虾米网》,纯" + '\n' + "属个人娱乐作品,有不足出错的地方请见谅.");
        }

        }
       
    }

  

 

posted @ 2011-08-10 14:27  wxdtk1989  阅读(2954)  评论(26编辑  收藏  举报