呈現IsolatedStorage中的多媒體資

来源:互联网 发布:音频剪辑合成软件 mac 编辑:程序博客网 时间:2024/04/27 22:30
 

熟悉WP7程序设计的开发人员大概都知道,IsolatedStorage是我们在WP7程序设计中存放数据的储存区,也是目前开发WP7唯一可以存放数据的位置。而数据存入IsolatedStorage中总是要读取出来,但是不同类型的数据,在读取时也有所不同。

举例来说,同样存放于IsolatedStorage中的图档、影音档,在不同的情况下使用的方式也不同。若是以图文件来说,要透过Image控件显示某个存放于IsolatedStorage中的图档,其程序代码如下:

System.IO.IsolatedStorage.IsolatedStorageFile iso = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();//開檔var fs1 = iso.OpenFile("Pic1.jpg", System.IO.FileMode.Open);//顯示jpgSystem.Windows.Media.Imaging.BitmapImage BitmapImage1=    new System.Windows.Media.Imaging.BitmapImage();BitmapImage1.SetSource(fs1);image1.Source = BitmapImage1;

如果是多媒体档案,因为是透过MediaElement来显示,所以程序代码就变成底下这样:

System.IO.IsolatedStorage.IsolatedStorageFile iso = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();//開檔var fs2 = iso.OpenFile("Nokia Lumia 800.mp4", System.IO.FileMode.Open);//顯示mp4mediaElement1.SetSource(fs2);

 

如果是使用MediaPlayerLauncher,用系统内建的拨放器来拨放位于IsolatedStorage中的影片呢? 程序代码又变成底下这样:

Microsoft.Phone.Tasks.MediaPlayerLauncher mp = new Microsoft.Phone.Tasks.MediaPlayerLauncher();//撥放isolatedStorage中的影片mp.Media = new Uri("Nokia Lumia 800.mp4", UriKind.Relative);mp.Show();


 

很有趣,还是很讨厌? 由于使用的拨放方式不同,处理的媒体类型不同,使用的程序代码也有所不同。

在WP7当中,原则上,谈到了uri,绝对位置Always是指向http远程的,问题不大,但是如果是近端(Relative, 指向手机上),则有许多不同的位置需要存取,Content(项目中的Content)、IsolatedStorage、Embedded Resource...etc, 不同的位置存取的方式也不同...

本周五,在微软的研讨会,我们先从WP7的远程与近端数据存取、DataBinding谈起,3月另一场研讨会,我们会继续来讨论这些多媒体数据存取的问题...