2

I'm basically asking the same thing that was asked here, however, that question was asked 8 years ago and the answer is no longer applicable to UWP.

I have a audio stream with http://someurl.com/stream that streams in audio/ogg format. I would like to be able to play that from an UWP app.

I see the NAudio library recommended a lot (after all, it's used in the above example), however it's very larger and has fairly lackluster documentation and very few up-to-date examples (they used to have a streaming example, but from what I'm able to download off Codeplex, it was replaced with a regular local-file player example). I'm not experience enough to make sense of the little documentation and example code they do have.

I'm honestly not even sure where to begin. I've never handled a stream like this (or any stream). Maybe the NAudio library isn't the way to go?

Code would be appreciated, but even pointers to sources where I could read up on playing such stream would be very helpful as my google-fu has failed me.

Thank you.


EDIT:

private void PlayMedia() {
    System.Uri manifestUri = new Uri("http://amssamples.streaming.mediaservices.windows.net/49b57c87-f5f3-48b3-ba22-c55cfdffa9cb/Sintel.ism/manifest(format=m3u8-aapl)");
    var mediaPlayer = new Windows.Media.Playback.MediaPlayer();
                                                 ~~~~~~~~~~~~ -> "'Media Player' does not contain a constructor that takes 0 arguments."
    mediaPlayer.Source = MediaSource.CreateFromUri(manifestUri);
    mediaPlayer.Play();
}
rancor1223
  • 356
  • 2
  • 16
  • Did you try [this]( https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/adaptive-streaming) ? – AVK Apr 12 '17 at 00:04
  • Yes, but I can't get the MediaPlayer class to work. It says for example the x.Play() doesn't exist. I think it's because I'm not correctly extending the class, but it's not recognizing the other classes for me. Im not sure what's wrong with it. – rancor1223 Apr 12 '17 at 05:22

1 Answers1

4

but I can't get the MediaPlayer class to work. It says for example the x.Play() doesn't exist.

You have not posted your code segment. So I could not locate the problem of Visual Studio alerting "doesn't exist" accurately. If you want to use "MediaPlayer" class please add Windows.Media.Core and Windows.Media.Playback namespace at first. And you could reference the following code implementing a basic mediaplayer.

using Windows.Media.Core;
using Windows.Media.Playback;

......

private void PlayMedia()
 {
     System.Uri manifestUri = new Uri("http://amssamples.streaming.mediaservices.windows.net/49b57c87-f5f3-48b3-ba22-c55cfdffa9cb/Sintel.ism/manifest(format=m3u8-aapl)");
     var mediaPlayer = new MediaPlayer();       
     mediaPlayer.Source = MediaSource.CreateFromUri(manifestUri);
     mediaPlayer.Play();
 }

The error message of Media Player does not contain a constructor that takes 0 arguments is means that there is no constructor with no arguments in the MediaPlayer class. Please try use the full name of constructor with namespace.

var mediaPlayer = new Windows.Media.Playback.MediaPlayer();       
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • Sorry, I didn't remember the error exactly (as I was fiddling with it there was a few of them, most of my own doing). Anyway, using the code you wrote gives me an error. I have updated my question with the code and the error message. – rancor1223 Apr 12 '17 at 20:39
  • So, that did nothing unfortunately. I tried making a Blank project and it worked fine there. I tried making new Minimal Template10 project (which I was using initially) and it didn't work again. Possibly a problem with T10? Anyway, I tried T10 in VS2017 and it seems to be working, so I guess it's fine now. I do wonder why this happens though. – rancor1223 Apr 13 '17 at 16:45