问题
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));
}
回答1:
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();
来源:https://stackoverflow.com/questions/24466936/how-do-you-automatically-openplay-file-after-it-is-saved-to-isolation-storage