Copying and Playing of an mp3 from a URL in Windows Phone 8

Posted by Vuyiswamb under Mobile Development on 11/9/2013 | Points: 10 | Views : 1056 | Status : [Member] [MVP] [Administrator] | Replies : 0
Good Day All

I am trying to stream an mp3 from a URL , So i first wanted to download the file first into the Isolated Storate or Local Storage and start to play the file. Below is the code i use to copy the File locally

   public static void  CopyToIsolatedStorage(string _fileName)
List<string> MyList = new List<string>();

foreach (var item in MyList)
using (IsolatedStorageFile localFile = IsolatedStorageFile.GetUserStoreForApplication())

Uri uri = new Uri(_fileName, UriKind.Absolute);
HttpWebRequest request = HttpWebRequest.Create(uri) as HttpWebRequest;
request.BeginGetResponse((ar) =>
var response = request.EndGetResponse(ar);
Deployment.Current.Dispatcher.BeginInvoke(() =>
using (var stream = response.GetResponseStream())
var name = GetFileNameinURL(item);
if (localFile.FileExists(name))
using (IsolatedStorageFileStream fs = localFile.CreateFile(name))

}, null);


and i try to play it like this

    private void btnPlay_Click(object sender, RoutedEventArgs e)
{ Button button = sender as Button;

//Copy file to Temp isolated Storate as Files can only play if they are in the Isolated Storage
GenericFunctions.CopyToIsolatedStorage(button.Tag.ToString()); //eg. url
//<MediaElement Name="media" />
media.Source = new Uri(GenericFunctions.GetFileNameinURL(button.Tag.ToString()));
media.Volume = 1;


Thank you for posting at Dotnetfunda


(No response found.)

Login to post response