read an mp3 file wiht mediaplayer in application metro RRS feed

  • Question

  • hello everybody!!

    I need to read an mp3 file from my MusicLibrary with mediaplayer..her is my code :

     StorageFolder musicFolder = KnownFolders.MusicLibrary;
                    IReadOnlyList<StorageFile> fileList = await musicFolder.GetFilesAsync();
                    foreach (var file in fileList)
                        mediaFilesOnComputer.Add(new Music_Track() { Title = file.Name, PlayURL = file.Path });
     var adURL = (from m in mediaFilesOnComputer
                                             where m.Title == titleMusicsListView.SelectedItem.ToString()
                                             select m.PlayURL).FirstOrDefault().ToString();
                                player.Source = new Uri(player.BaseUri, @adURL);

    Unfortunately it doesn't work ...the player.Source has his value : "file:///C://...."

    I tride to do this but is still not working :

    player.Source = new Uri( @adURL, UriKind.Relative);

    player.Source = new Uri( @adURL, UriKind.Absolute);

    Somebody may help please?


    • Edited by DiddyRennes Friday, May 25, 2012 2:53 PM Completed
    Friday, May 25, 2012 2:46 PM


  • Your application doesn't have direct access to files in the Music Library, so it cannot reference them by path. To access the file contents you need to open the stream provided by the StorageFile object. You can pass the stream to MediaElement.SetSource()

    Metro style applications have direct access to files only in their installed and application data directories. Other areas accessed through Capabilities or pickers are brokered by a separate process which has wider file access privileges. This broker reads the files for you and provides their contents as a stream.


    Friday, May 25, 2012 2:56 PM