I have downloaded a .mp3 Song in my application using HttpWebRequest and WebClient Both.
I am saving the response stream in Isolated Storage with .mp3 extension filename.
When i m trying to play it with BackgroundAudioPlayer
it do not plays.
Here is my code. Please suggest what is wrong with it.
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();
}
}
}
The way i m saving the Downloaded stream into IsolatedStorage
is given below.
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();
}
}
}
}
}
Please suggest what is wrong with this code.
Here is the Xaml code for ListBox containing my file names.
<ListBox Name="lstBoxSongList" SelectionChanged="lstBoxSongList_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>