user10050856
user10050856

Reputation:

How do i get an item from a list into StorageFile type?

How to play a song from playlist when a user clicks on it? Everything file related in UWP is storageFile type. How do I give the media player a stream from a StorageFile?

Upvotes: 0

Views: 55

Answers (1)

lindexi
lindexi

Reputation: 4357

How to play a song from playlist when a user clicks on it?

You should define a list to bind to list control(ListView) and then bind the command when the user clicks the Item. And you should write something in the command code to play the song.

Everything file related in UWP is storageFile type.

Good. You can bind the StorageFile as the property in Item and you can know which item the user clicks on.

How do I give the media player a stream from a StorageFile?

You should play the song by MediaPlayer that can set the source. If the StorageFile which the user clicks on is file and you should use this code to set the source.

 MediaPlayerElement.Source = MediaSource.CreateFromStorageFile(file);
 MediaPlayerElement.MediaPlayer.Play();

See https://learn.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/media-playback

Upvotes: 1

Related Questions