Search code examples
c#windows-phone-8isolatedstorage

How do you Automatically open(play) file after it is saved to isolation storage? WP8


I think it should go somewhere in the OpenReadCompleted event but nothing I have tried is working. The code below includes the portion where if the file already exists, it will Play, which works. But I would like it to also play automatically after initially downloading.

audioStream = IsolatedStorageFile.GetUserStoreForApplication().OpenFiledata.SavePath,FileMode.Open, FileAccess.Read, FileShare.Read);    

AudioPlayer.SetSource(audioStream);
AudioPlayer.Play();
}
else
{

            WebClient client = new WebClient();
            client.OpenReadCompleted += (senderClient, args) =>
                {
                    using (IsolatedStorageFileStream fileStream = IsolatedStorageFile.GetUserStoreForApplication().CreateFile(data.SavePath))  
                    {
                        args.Result.Seek(0, SeekOrigin.Begin);
                        args.Result.CopyTo(fileStream);
                    }
                };
            client.OpenReadAsync(new Uri(data.FilePath));
}

Solution

  • I could have swore I tried this earlier and it didn't work. Here was my solution. Added AudioPlayer code after args like so:

         using (IsolatedStorageFileStream fileStream =  IsolatedStorageFile.GetUserStoreForApplication).CreateFile(data.SavePath))                     
    {                         
    args.Result.Seek(0, SeekOrigin.Begin);
    args.Result.CopyTo(fileStream);
    AudioPlayer.SetSource(fileStream); 
    AudioPlayer.Play();