1

I have been discussing this topic on another forum and no one could actually help, let's see if someone here can.

I Have a Problem with the URI you get from the Soundcloud Api to play a song. On my dekstop this Command:

mediaelement.Source = new Uri("https://api.soundcloud.com/tracks/218090824/stream?client_id=YOUR_CLIENT_ID");
mediaelement.Play();

works just fine, on the PI it doesn't at all, no clue why.

I have a workaround for now which looks like this:

            Uri turi = new Uri("https://api.soundcloud.com/tracks/218090824/stream?client_id=YOUR_CLIENT_ID");

            IRandomAccessStreamReference rsr = RandomAccessStreamReference.CreateFromUri(turi);
            PBar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            StorageFile file1 = await StorageFile.CreateStreamedFileFromUriAsync("test mp3", turi, rsr);
            IRandomAccessStream stream = await file1.OpenReadAsync();

            PBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            mediaElement.PosterSource = img;
            mediaElement.SetSource(stream, "audio/mp3");
            mediaElement.Play();

The Problem here is that the files are being downloaded before they are played, this is not a problem if the songfile is <10 mb but with mixtapes >100 mb this takes a long time. So Is it somehow possible to get an IRandomAccessStream from the URI which can be played while being downloaded?

This Solution:

 HttpClient httpClient = new HttpClient();
        HttpResponseMessage response = await httpClient.GetAsync("https://api.soundcloud.com/tracks/218090824/stream?client_id=YOUR_CLIENT_ID", HttpCompletionOption.ResponseHeadersRead);
        HttpResponseMessage rs = await httpClient.GetAsync(response.RequestMessage.RequestUri, HttpCompletionOption.ResponseHeadersRead);
        Stream stream = await rs.Content.ReadAsStreamAsync();
        IRandomAccessStream content = stream.AsRandomAccessStream();
        mediaElement.SetSource(content, "audio/mpeg");

doesn't work because I get an error when i want to convert the Stream to IRandomAccessStream which says: ""Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking."

Eych
  • 313
  • 1
  • 5
  • 14
  • check this link regarding the exception you are getting maybe change the conversion of the streams with one of the solutions provided http://stackoverflow.com/questions/7669311/is-there-a-way-to-convert-a-system-io-stream-to-a-windows-storage-streams-irando – Overmachine Sep 23 '15 at 16:43
  • Tried that one already, if i do that then i have the same problem with waiting, because the stream is being copied. – Eych Sep 23 '15 at 16:51

1 Answers1

0

Issue has been resolved with the latest Windows IOT Update.

Eych
  • 313
  • 1
  • 5
  • 14
  • mediaelement.Source = new Uri("https://api.soundcloud.com/tracks/218090824/stream?client_id=YOUR_CLIENT_ID"); mediaelement.Play(); – Eych Dec 14 '15 at 12:47