我正在从 Web 服务读取保存为字节流的 wav 文件,并希望在显示我的记录时播放它。电话 7 应用程序。
我的方法是在导航到记录时将字节流保存到隔离存储中的 wav 文件,然后在单击按钮并播放它时将我的媒体播放器 (MediaElement1) 的源设置为该源。
以下是我的“PlayButton”中的当前代码。(大小匹配字节流但没有音频结果)。如果我将流设置为存储为资源的 WAV 文件,它确实可以工作,所以也许我只需要知道如何将 Uri 设置为独立存储文件。
(例如以下代码有效)
Mediaelement1.Source = new Uri("SampleData\\MyMedia.wav",UriKind.Relative) Works
Mediaelement1.Position = new TimeSpan(0,0,0,0) ;
Mediaelement1.Play() ;
这是我的代码示例......有什么想法吗?
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication() ;
IsolatedStorageFileStream str = new IsolatedStorageFileStream(
"MyMedia.wav", FileMode.Open, isf) ;
long size = str.Length;
mediaelement mediaelement = new MediaElement() ;
mediaelement.SetSource(str) ;
mediaElement1.Source = mediaelement.Source ;
mediaElement1.Position = new TimeSpan(0, 0, 0, 0);
mediaElement1.Play();