uwp----player 2

My player 2 github: https://github.com/xiongxlxhm/play

Increase the function of the player

  • Online Play: Play online audio directly
  • Cache and Play: Download online audio to the music folder, then play the file

      The player I made last time, I don't think he is beautiful. So I used the SplitView taught by the teacher in the class this time. In the class, I just listened to the teacher, but I didn't try it myself, so I decided to use the frame to call the pages of each function, but the imagination is always beautiful, what I did is ugly. I made three new pages to play music, video and download music respectively.

 

Click on the menu button, there are four function options.

 

one. online

   Click the "Online" button to jump to the web page and play our school song.

This function is relatively simple to do. I found it online

https://social.msdn.microsoft.com/Forums/zh-CN/f1736e5b-619a-4533-8a28-5286f5eac6f2/windows-10-uwp?forum=windowsphonezhchs&forum=windowsphonezhchs

This site is looking for. MP4's, but MP3's are the same.

 

await  Windows.System.Launcher.LaunchUriAsync(new Uri("http://a.b.com/a.mp4"), new Windows.System.LauncherOptions() { ContentType = "video/mp4" });

He introduced a code like this, I tried to use it, and added it to the click event of the button. It was ok and I solved it. But didn't understand anything, so I looked

https://msdn.microsoft.com/zh-cn/library/windows/apps/windows.system.aspx

Some of the introductions in this website are the Launcher.LaunchUriAsync | launchUriAsync method under the launcher class in windows.systeml. is to start the program associated with the specified uri scheme. In this way, you can access the online audio.

https://docs.microsoft.com/en-us/previous-versions/windows/apps/hh965322(v=win.10)

This page explains that you can access file resources in application files that are provided as part of an application package, or included in application data or the network as part of a component or framework package.

two. local selection

https://docs.microsoft.com/zh-cn/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries

This page is to add existing music, pictures and video folders to the corresponding library. You can also delete folders from your library, get a list of folders in your library, and discover stored photos, music, and videos.

Libraries are virtual collections of folders that include a default known folder and any other folders that users add to the library by using your app or one of the built-in apps. For example, the picture library contains the "pictures" known folder by default. Users can add or delete folders from their photo library by using your app or the built-in Photos app.

var myPictures = await Windows.Storage.StorageLibrary.GetLibraryAsync(Windows.Storage.KnownLibraryId.Pictures);

            Windows.Storage.StorageFolder savePicturesFolder = myPictures.SaveFolder;

            Windows.Storage.StorageFolder newFolder = await myPictures.RequestAddFolderAsync();

 

            QueryOptions queryOption = new QueryOptions

                (CommonFileQuery.OrderByTitle, new string[] { ".mp3", ".mp4", ".wma" });

 

            queryOption.FolderDepth = FolderDepth.Deep;

 

            Queue<IStorageFolder> folders = new Queue<IStorageFolder>();

 

            var files = await KnownFolders.MusicLibrary.CreateFileQueryWithOptions

              (queryOption).GetFilesAsync();

By writing the above statements, the function of selecting files in the library can be realized.

 

https://blog.csdn.net/u011033906/article/details/65447199

Here we talk about file and open library.

 

 

 

 

three. download

I have implemented this download function, and I really have been doing it for a long time. I found a lot of information, I just looked for how to download, and I came across this page

https://blog.csdn.net/lindexi_gd/article/details/53425673

But this page is about downloading pictures, but I think it should be the same, just take a look, but I gave up in the end. Most of the Internet is based on downloading pictures as an example. I really do it. I didn't understand, so I asked my classmates to ask how he did it. He told me to go to the Microsoft website that I had seen before.

https://docs.microsoft.com/zh-cn/windows/uwp/files/quickstart-managing-folders-in-the-music-pictures-and-videos-libraries

然后我就这个网页里说了一步步做下来,就是可以找到了本地的图片和音频等,我就把他放到了我的功能二----本地选择。

但是看到最后,使用流方法向媒体库添加文件,但我还是不会,不怎么弄,又在网上各种乱搜,找到了https://www.cnblogs.com/T-ARF/p/5886153.html

但是这里的代码我用到我的里就是有错,我就把代码放到网上搜一搜是怎么用的,我又看了

https://msdn.microsoft.com/zh-cn/library/system.net.http.httpclient.aspx

这里介绍了HttpClient()的用法。

代码里

public async Task<StorageFile> Load()

        {

            try

 

            {

                var httpClient = new Windows.Web.Http.HttpClient();

                var buffer = await httpClient.GetBufferAsync(new Uri("http://www.neu.edu.cn/indexsource/neusong.mp3"));

                if (buffer != null && buffer.Length > 0u)

                {

                    var file = await KnownFolders.MusicLibrary.CreateFileAsync("neusong.mp3", CreationCollisionOption.ReplaceExisting);

                    using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))

                    {

                        await stream.WriteAsync(buffer);

                        await stream.FlushAsync();

                    }

                    return file;

                }

            }

            catch { }

            return null;

        }

最后返回了file,应该可以到文件了,我就研究文件

https://blog.csdn.net/u011033906/article/details/65447199

这里讲里文件,最后将缓存的文件播放出来。将neusong.mp3下载到音乐文件夹

 

在使用MediaElement的时候有问题,我就看了

 

https://msdn.microsoft.com/zh-tw/library/windows/apps/mt187272.aspx

 

通过调用SetSource方法来找播放源。

 

 

在下载的这个功能里,我真的费了很久的时间,与同学交流的很多菜搞懂了下载的这个过程。也试了

https://docs.microsoft.com/en-us/uwp/api/windows.networking.backgroundtransfer.backgrounddownloader

这个网址里讲的后台下载,但是也是有点难懂,没有成功。

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324385908&siteId=291194637
UWP