如何将文件保存到隔离存储后自动打开(播放)文件? WP8

时间:2014-06-28 12:44:40

标签: c# windows-phone-8 isolatedstorage

我认为它应该在OpenReadCompleted事件的某个地方,但我尝试过的任何工作都没有。下面的代码包括文件已存在的部分,它将播放,哪个有效。但是我希望它在最初下载后也能自动播放。

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 个答案:

答案 0 :(得分:1)

我可以发誓我早些时候试过这个并没有用。这是我的解决方案。在args之后添加了AudioPlayer代码:

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