C# 下载的mp3流未从windows phone 7中的隔离存储播放
我在应用程序中使用HttpWebRequest和WebClient下载了一首.mp3歌曲。 我正在使用.mp3扩展名将响应流保存在独立存储中。 当我尝试使用C# 下载的mp3流未从windows phone 7中的隔离存储播放,c#,windows-phone-7,windows-phone-8,httpwebrequest,webclient,C#,Windows Phone 7,Windows Phone 8,Httpwebrequest,Webclient,我在应用程序中使用HttpWebRequest和WebClient下载了一首.mp3歌曲。 我正在使用.mp3扩展名将响应流保存在独立存储中。 当我尝试使用BackgroundAudioPlayer播放时,它不会播放 这是我的密码。请说明它有什么问题 using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { if (store.FileExists(lstBoxSon
BackgroundAudioPlayer播放时,它不会播放
这是我的密码。请说明它有什么问题
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists(lstBoxSongList.SelectedItem as string))
{
using (IsolatedStorageFileStream isfStream = store.OpenFile(lstBoxSongList.SelectedItem.ToString(), FileMode.Open, FileAccess.Read))
{
AudioTrack track = new AudioTrack(new Uri(lstBoxSongList.SelectedItem as string, UriKind.RelativeOrAbsolute), lstBoxSongList.SelectedItem.ToString(), "", "", null);
BackgroundAudioPlayer.Instance.Track = track;
BackgroundAudioPlayer.Instance.Volume = 1;
BackgroundAudioPlayer.Instance.Play();
}
}
}
下面给出了我将下载的流保存到IsolatedStorage
中的方法
webClient.OpenReadCompleted += (s1, e1) =>
{
if (e1.Error == null)
{
bool isSpaceAvailable = IsSpaceIsAvailable(e1.Result.Length);
if (isSpaceAvailable)
{
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
// Save mp3 to Isolated Storage
if (store.FileExists(filename))
{
store.DeleteFile(filename);
}
using (var isfs = new IsolatedStorageFileStream(filename, FileMode.CreateNew, IsolatedStorageFile.GetUserStoreForApplication()))
{
long fileLen = e1.Result.Length;
byte[] b = new byte[fileLen];
e1.Result.Read(b, 0, b.Length);
isfs.Write(b, 0, b.Length);
isfs.Flush();
}
}
}
}
}
请说明此代码的错误
下面是包含我的文件名的ListBox的Xaml代码
<ListBox Name="lstBoxSongList" SelectionChanged="lstBoxSongList_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
能否添加列表框的XAML代码?我认为您检索的项目名称不正确way@fillobotto我在问题中添加了listbox的xaml代码。