简体   繁体   English

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

[英]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. 我认为它应该在OpenReadCompleted事件中的某个地方,但是我尝试过的任何方法都没有用。 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));
}

I could have swore I tried this earlier and it didn't work. 我本可以发誓早些尝试过,但没有成功。 Here was my solution. 这是我的解决方案。 Added AudioPlayer code after args like so: 在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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM