呈現IsolatedStorage中的多媒體資

 

熟悉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);
//顯示jpg
System.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);
//顯示mp4
mediaElement1.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月另一场研讨会,我们会继续来讨论这些多媒体数据存取的问题...


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值