2

I am building an audio streaming app using Windows 10 UWP MediaPlayer. Most streams are of type shoutcast/icecast mp3-stream with metadata about the program embedded in the stream itself.

My code for playing an audiostream is essentially like this:

mediaPlayer.Source = MediaSource.CreateFromUri(channelUri);
mediaPlayer.Play();

While I am perfectly capable of opening the same stream-url with a HttpClient, parsing the metadata and reading the info, this is not what I want. I need to get metadata every 10 sec or so and don't want to have two simultaneous sessions.

So I have two questions:

  1. Is the UWP MediaPlayer component capable of reading the metadata, and if so, how?
  2. If not, is it possible for me to open the stream via httpclient (or something else), read the metadata, then send the same stream to the MediaPlayer?

Example stream: http://sverigesradio.se/topsy/direkt/164-hi-mp3

Tommy Ovesen
  • 400
  • 3
  • 11

1 Answers1

1

I've never used UWP, but I have a solution for you coming from a web development perspective, and it looks like UWP is using a very similar API.

Is the UWP MediaPlayer component capable of reading the metadata, and if so, how?

Probably not. None of the Microsoft code I've seen does. None of the web browsers' media players handle this natively either.

If not, is it possible for me to open the stream via httpclient (or something else), read the metadata, then send the same stream to the MediaPlayer?

Yes, this is exactly what you should do.

Use MediaSource Extensions. MSE, at least in a web browser context, allows you to get your media data using whatever means you want, and then pass it into the media player to let it run it through the codec and playback.

In browsers, you would use the Fetch API to make your HTTP request with the Icy-MetaData: 1 header to request the metadata from the server, read the Icy-MetaInt response header to determine the byte offsets for the metadata chunks, and then demux the metadata from the audio data before dropping the audio data into a buffer to be sent to the media player.

Some resources to get you started for UWP:

Sorry I cannot give you more specific code for UWP!

Brad
  • 159,648
  • 54
  • 349
  • 530