How to play file from Library by MediaElement?

前端 未结 1 341
误落风尘
误落风尘 2020-12-21 12:41

I can play files only from application storage, but, I have to play file from Library or another source. The I try to:

        var storageFile = await Storag         


        
相关标签:
1条回答
  • 2020-12-21 13:36

    If you want to play audio files from library, then you need to use KnownFolders. GetFileFromApplicationUriAsync won't work.

    var storageFile = await KnownFolders.MusicLibrary.GetFileAsync("line.mp3");
    var stream = await storageFile.OpenAsync(FileAccessMode.Read);
    mediaElement.SetSource(stream, storageFile.ContentType);
    mediaElement.Play();
    

    If you want enumerate all the media file or all the folders then use this.

    var AllStorageFiles = await KnownFolders.MusicLibrary.GetFilesAsync();
    var AllStorageFolders = await KnownFolders.MusicLibrary.GetFoldersAsync();
    
    0 讨论(0)
提交回复
热议问题