我一直在另一个论坛上讨论这个话题,没有人能真正帮助,让我们看看这里是否有人可以。SoundCloud Stream_url无法在Raspberry Pi上工作
我对从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();
这里的问题是,在播放之前,他们的文件被下载,这不是一个问题,如果songfile是< 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");
不工作,因为我得到一个错误,当我想给流转换为IRandomAccessStream它说:“”不能使用指定的流作为Windows运行时IRandomAccessStream因为此流不支持查找“
检查关于你正在也许改变流的转换与HTTP提供的解决方案之一外,这个环节得到了解决:// stackover flow.com/questions/7669311/is-there-a-way-to-convert-a-system-io-stream-to-a-windows-storage-streams-irando – Overmachine
试过那个,如果我那样做了我有同样的问题等待,因为流正在被复制。 – Eych