音乐播放器页面之音频播放页面设计

1.引言

    本篇将介绍音频播放页面的统筹意况,也期待能将团结的体会与我们大饱眼福。

2.企划情状

2.1 总体设计

    XAML页面如下:

 <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.Resources>
            <cvt:MusicConverter x:Key="MusicPostionConverter"/>
        </Grid.Resources>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="MediaGrid" Height="*"/>
            <RowDefinition x:Name="PlayerPostionGrid" Height="40"/>
            <RowDefinition x:Name="BttnGrid" Height="Auto"/>
        </Grid.RowDefinitions>
        <Border BorderThickness="1">
            <MediaElement x:Name="MediaPlayer" Stretch="Fill" VerticalAlignment="Center" HorizontalAlignment="Center" MediaOpened="MediaPlayer_MediaOpened" MediaEnded="MediaPlayer_MediaEnded" />
        </Border>
        <RelativePanel Grid.Row="1" >
            <Slider x:Name="PlayerPostion" Height="40" VerticalAlignment="Center" RelativePanel.AlignTopWithPanel="True" Value="{Binding ElementName=MediaPlayer,Path=Position, Converter={StaticResource MusicPostionConverter}, Mode=TwoWay}" Minimum="0.0" />
        </RelativePanel>
        <RelativePanel Grid.Row="2">
            <ToggleSwitch x:Name="SwtchMediaRepeat" OffContent="单曲循环" OnContent="顺序循环" HorizontalAlignment="Left"  VerticalAlignment="Center" RelativePanel.AlignLeftWithPanel="True"/>
            <StackPanel Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" Orientation="Horizontal" RelativePanel.AlignHorizontalCenterWithPanel="True" RelativePanel.AlignVerticalCenterWithPanel="True" >
                <Button x:Name="BttnPrevious" FontFamily="Segoe MDL2 Assets" Content="&#xEDD9;" Click="BttnPrevious_Click"/>
                <Button x:Name="BttnPlay" FontFamily="Segoe MDL2 Assets" Content="&#xEDB4;" Click="BttnPlay_Click"/>
                <Button x:Name="BttnStop" FontFamily="Segoe MDL2 Assets" Content="&#xEDB5;" Click="BttnStop_Click"/>
                <Button x:Name="BttnNext" FontFamily="Segoe MDL2 Assets" Content="&#xEDDA;" Click="BttnNext_Click"/>
            </StackPanel>
            <TextBlock Grid.Column="2" FontFamily="Segoe MDL2 Assets" Text="&#xE953;" HorizontalAlignment="Left"  VerticalAlignment="Center" Tapped="TextBlock_Tapped" RelativePanel.AlignRightWithPanel="True" Margin="0,15,30,0" >
                    <FlyoutBase.AttachedFlyout>
                        <Flyout>
                              <Slider x:Name="SldrVolume" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center" Width="50" ValueChanged="SldrVolume_ValueChanged" Value="50" Minimum="0.0" Maximum="100.0"/> 
                        </Flyout>
                    </FlyoutBase.AttachedFlyout>
            </TextBlock>
        </RelativePanel>
    </Grid>

在那里自己将那些页面分成三行,第二行的惊人为40,第三行的可观为Auto,其他高度都分配到第一行。第一行放MeidElement控件,用于广播音频文件,第二行放Silder控件,用于体现音频文件的广播进程,第三行则相继放入播放顺序、播放按钮和音量调节按钮。

2.2 悬浮的轻重调节控制

    总体的页面设计相比较不难,个人觉得悬浮的音量调节控制算得上一个独到之处。效果不难演示一下:

图片 1

此处其实是行使了Flyout这么些控件。对于Button控件而言,可以间接行使Button.Flyout属性,在Button的Click事件中,Flyout控件会自行打开。但是对于非Button控件而言,只好通过FlyoutBase.AttachedFlyout附件属性。以TextBlock为例,代码如下:

XAML语法

<TextBlock Text="Tapped事件触发Flyout" Tapped="TextBlock_Tapped">
    <FlyoutBase.AttachedFlyout>
        <Flyout>
            <!-- 浮出的UI内容 -->
        </Flyout>
    </FlyoutBase.AttachedFlyout>
</TextBlock>

C#代码

private void TextBlock_Tapped(object sender,TappedRoutedEventArgs e)
{
    FrameworkElement element = sender as FrameworkElement;
    if(element != null)
    {
        FlyoutBase.ShowAttchedFlyout(element);
    }
}

    Flyout控件一起有6种不一致的项目:Flyout、DatePicker、提姆ePickerFlyout、PlickerFlyout、ListPickerFlyout和MenuFlyout。那几个Flyout控件具体行使本篇则不涉及了。

2.3 MusicConverter

    Grid.Resources下的Converter是节奏播放进程与Silder控件PlayerPostion的Value值的竞相转化,涉及到多少绑定的学识,那里暂时不涉及。

3.效率演示

图片 2

相关文章