我想在我的Windows手机应用中播放shoutcast音频。我从一些网站获得了以下代码。
namespace WPBackgroundAudioDemo
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
SaveToIsoStore();
}
private void buttonStart_Click(object sender, RoutedEventArgs e)
{
if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Playing )
BackgroundAudioPlayer.Instance.Play();
}
private void buttonStop_Click(object sender, RoutedEventArgs e)
{
if (BackgroundAudioPlayer.Instance.PlayerState != PlayState.Stopped)
BackgroundAudioPlayer.Instance.Stop();
}
private void SaveToIsoStore()
{
IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication();
if (!isolatedStorageFile.FileExists("Lullabies.mp3"))
{
StreamResourceInfo resource = Application.GetResourceStream(new Uri("Lullabies.mp3", UriKind.Relative));
using (IsolatedStorageFileStream isolatedStorageFileStream = isolatedStorageFile.CreateFile("Lullabies.mp3"))
{
int chunkSize = 1024;
byte[] bytes = new byte[chunkSize];
int byteCount;
while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
{
isolatedStorageFileStream.Write(bytes, 0, byteCount);
}
}
}
}
}
}
现在,问题在于此示例播放内部文件。因为我是Windows的新手,所以我无法理解为这个玩家提供一个shoutcast网址应该遵循什么。请帮助通过URL在BackgroundAudioPlayer中播放音频。任何形式的帮助,因为我迫切需要这个。提前完成所有人..
答案 0 :(得分:0)
您基本上创建了一个AudioTrack并将其传递给播放器。像
var track =
new AudioTrack(
new Uri(your url here, UriKind.Absolute),
"Track Name",
string.Empty,
string.Empty,
null);
BackgroundAudioPlayer.Instance.Track = track;
BackgroungAudioPlayer.Instance.Play();
答案 1 :(得分:0)
private static List<AudioTrack> _playList = new List<AudioTrack>
{
new AudioTrack(new Uri("Default Project.aac", UriKind.Relative),
"Kalimba",
"Mr. Scruff",
"Ninja Tuna",
null),
new AudioTrack(new Uri("Rainy Mood + The Cinematic Orchestra.aac", UriKind.Relative),
"Maid with the Flaxen Hair",
"Richard Stoltzman",
"Fine Music, Vol. 1",
null),
new AudioTrack(new Uri("Rainy Mood + The Cinematic Orchestra.aac", UriKind.Relative),
"Sleep Away",
"Bob Acri",
"Bob Acri",
null),
// A remote URI
new AudioTrack(new Uri("http://traffic.libsyn.com/wpradio/WPRadio_29.mp3", UriKind.Absolute),
"Episode 29",
"Windows Phone Radio",
"Windows Phone Radio Podcast",
null)
};