SoundCloud Stream_url不适用于Raspberry Pi

时间:2015-09-23 16:27:06

标签: c# raspberry-pi soundcloud mediaelement

我一直在另一个论坛讨论这个话题,没有人能真正帮助,让我们看看这里有人可以。

我对使用Soundcloud Api播放歌曲的URI有疑问。在我的dekstop这个命令:

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

工作得很好,在PI上它完全没有,没有线索的原因。

我现在有一个解决方法,如下所示:

            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();

这里的问题是文件在播放之前正在下载,如果歌曲文件<10 mb但是混音带> 100 mb则这不是问题,这需要很长时间。那么以某种方式从URI中获取IRandomAccessStream是否可以在下载时播放?

此解决方案:

 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");

无法正常工作,因为当我想将Stream转换为IRandomAccessStream时出现错误:&#34;&#34;无法将指定的Stream用作Windows运行时IRandomAccessStream,因为此Stream不支持寻求&#34;

1 个答案:

答案 0 :(得分:0)

使用最新的Windows IOT更新解决了问题。