xml地图|网站地图|网站标签 [设为首页] [加入收藏]

您的位置:凤凰彩票app下载 > 音乐 > 重新想象 Windows 8 Store Apps (65) - 后台任务: 音乐的

重新想象 Windows 8 Store Apps (65) - 后台任务: 音乐的

发布时间:2019-10-08 12:24编辑:音乐浏览(87)

    [源码下载]

    [源码下载]凤凰彩票app,

    重新想象 Windows 8 Store Apps (65) - 后台任务: 音乐的后台播放和控制

    重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传

    作者:webabcd

    作者:webabcd

    介绍
    重新想象 Windows 8 Store Apps 之 后台任务

    介绍
    重新想象 Windows 8 Store Apps 之 后台任务

    • 音乐的后台播放和控制
    • 后台下载任务
    • 后台上传任务

    示例
    用于保存每首音乐的相关信息的对象
    BackgroundTask/SongModel.cs

    示例
    扩展了 DownloadOperation 和 UploadOperation,以便下载进度或上传进度可通知
    BackgroundTask/TransferModel.cs

    /*
     * 用于保存每首音乐的相关信息
     */
    
    using System;
    using System.Threading.Tasks;
    using Windows.Storage;
    
    namespace XamlDemo.BackgroundTask
    {
        public class SongModel
        {
            /// <summary>
            /// 音乐文件
            /// </summary>
            public StorageFile File;
    
            /// <summary>
            /// 艺术家
            /// </summary>
            public string Artist;
    
            /// <summary>
            /// 音乐名称
            /// </summary>
            public string Title;
    
            public SongModel(StorageFile file)
            {
                File = file;
            }
    
            /// <summary>
            /// 加载音乐的相关属性
            /// </summary>
            public async Task LoadMusicPropertiesAsync()
            {
                var properties = await this.File.Properties.GetMusicPropertiesAsync();
    
                Artist = properties.Artist;
                Title = properties.Title;
            }
        }
    }
    
    /*
     * 扩展了 DownloadOperation 和 UploadOperation,以便下载进度或上传进度可通知
     */
    
    using System;
    using System.ComponentModel;
    using Windows.Networking.BackgroundTransfer;
    
    namespace XamlDemo.BackgroundTask
    {
        public class TransferModel : INotifyPropertyChanged
        {
            public DownloadOperation DownloadOperation { get; set; }
            public UploadOperation UploadOperation { get; set; }
    
            public string Source { get; set; }
            public string Destination { get; set; }
    
            private string _progress;
            public string Progress
            {
                get { return _progress; }
                set
                {
                    _progress = value;
                    RaisePropertyChanged("Progress");
                }
            }
    
            public event PropertyChangedEventHandler PropertyChanged;
            protected void RaisePropertyChanged(string name)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
        }
    }
    

    演示如何通过 MediaControl 实现音乐的后台播放和控制
    BackgroundTask/MediaControlDemo.xaml

    1、演示后台下载任务的应用
    BackgroundTask/TransferDownload.xaml

    <Page
        x:Class="XamlDemo.BackgroundTask.MediaControlDemo"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:XamlDemo.BackgroundTask"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="Transparent">
            <StackPanel Margin="120 0 0 0">
    
                <TextBlock Name="lblMsg" FontSize="14.667" />
    
                <Button Name="btnSelectFiles" Content="Select Files" Click="btnSelectFiles_Click" Margin="0 10 0 0" />
                <Button Name="btnPlay" Content="Play" Click="btnPlay_Click" Margin="0 10 0 0" />
    
                <!--
                    为了使音乐可以后台播放,需要将 MediaElement 的 AudioCategory 属性设置为 BackgroundCapableMedia
                -->
                <MediaElement Name="mediaElement" AudioCategory="BackgroundCapableMedia" AutoPlay="False" 
                              MediaOpened="mediaElement_MediaOpened" MediaEnded="mediaElement_MediaEnded" CurrentStateChanged="mediaElement_CurrentStateChanged" />
    
            </StackPanel>
        </Grid>
    
    </Page>
    
    <Page
        x:Class="XamlDemo.BackgroundTask.TransferDownload"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:XamlDemo.BackgroundTask"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d">
    
        <Grid Background="Transparent">
            <StackPanel Margin="120 0 0 0">
    
                <ScrollViewer Height="100">
                    <TextBlock Name="lblMsg" FontSize="14.667" TextWrapping="Wrap" />
                </ScrollViewer>
    
                <Button Name="btnAddDownload" Content="新增一个下载任务" Margin="0 10 0 0" Click="btnAddDownload_Click" />
                <Button Name="btnPause" Content="暂停所有下载任务" Margin="0 10 0 0" Click="btnPause_Click" />
                <Button Name="btnResume" Content="继续所有下载任务" Margin="0 10 0 0" Click="btnResume_Click" />
                <Button Name="btnCancel" Content="取消所有下载任务" Margin="0 10 0 0" Click="btnCancel_Click" />
    
                <ListView Name="listView" Padding="0 10 0 0" Height="300">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Margin="0 5" Background="Blue">
                                <TextBlock Text="{Binding Source}" Margin="5" />
                                <TextBlock Text="{Binding Destination}" Margin="5" />
                                <TextBlock Text="{Binding Progress}" Margin="5" />
                            </StackPanel>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
    
            </StackPanel>
        </Grid>
    </Page>
    

    本文由凤凰彩票app下载发布于音乐,转载请注明出处:重新想象 Windows 8 Store Apps (65) - 后台任务: 音乐的

    关键词:

上一篇:没有了

下一篇:没有了