SoundCloud Stream_url 不适用于 Raspberry Pi
SoundCloud Stream_url doesnt work on Raspberry Pi
我一直在另一个论坛上讨论这个话题,但没有人能真正提供帮助,让我们看看这里是否有人可以。
我对从 Soundcloud Api 获得的用于播放歌曲的 URI 有疑问。在我的桌面上这个命令:
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 时出现错误,其中显示:“"Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking."
问题已通过最新的 Windows IOT 更新解决。
我一直在另一个论坛上讨论这个话题,但没有人能真正提供帮助,让我们看看这里是否有人可以。
我对从 Soundcloud Api 获得的用于播放歌曲的 URI 有疑问。在我的桌面上这个命令:
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 时出现错误,其中显示:“"Cannot use the specified Stream as a Windows Runtime IRandomAccessStream because this Stream does not support seeking."
问题已通过最新的 Windows IOT 更新解决。