MediaElement 的 SetSource 使用继承自isolatedStorageFileStream 的自定义流
我有一个名为 XorIsoStoreFileStream 的类,它继承自isolatedStorageFileStream,重点是使用这个类,内容是用异或“加密”编写的,并且当它异或回来时也可以使用这个类读取它。例如:
public override int Read( byte[] buffer, int offset, int count )
{
int startbyte = (int)base.Position;
int readlength = base.Read( buffer, offset, count );
xor( startbyte, buffer );
return readlength;
}
这似乎在程序的其他地方都工作正常。现在我需要从那里播放一个 mp3 文件,并且由于重写了 Read 和 ReadByte,它应该像我给 SetSource 一个isolatedStorageFileStream 一样工作。不过,它不会占用我的 Xor 类。当我点击播放时,它在 SetSource 行处遇到 NotSupportedException,提示“Stream 必须是isolatedStorageFileStream 类型”。
using( var appStorage = IsolatedStorageFile.GetUserStoreForApplication() )
{
if( appStorage.FileExists( path ) )
{
using( var stream = new XorIsoStoreFileStream( path, FileMode.Open, appStorage ) )
{
App.MainAudioPlayer.SetSource( stream ); // how to put Xor stream here?
}
}
}
还有其他我可以覆盖的东西吗,比如 SetSource 本身?看起来这没什么帮助。
我必须实施 MediaStreamSource 吗?这似乎是一种巨大的杀伤力,重新发明轮子等等。
或者这根本行不通?我是否必须将文件的解密部分保存到临时位置并将 SetSource 保存到普通的isolatedStorageFileStream?
I have a class called XorIsoStoreFileStream inheriting from IsolatedStorageFileStream, and the point is that using this class, stuff is written with an XOR "encryption" and it can also be read using this class when it XORs it back. For example:
public override int Read( byte[] buffer, int offset, int count )
{
int startbyte = (int)base.Position;
int readlength = base.Read( buffer, offset, count );
xor( startbyte, buffer );
return readlength;
}
This seems to be working okay everywhere else in the program. Now I need to play an mp3 file from there, and because of the overridden Read and ReadByte, it should work just as if I'd given SetSource an IsolatedStorageFileStream. It will not take my Xor class though. When I hit play, it hits a NotSupportedException at the SetSource line saying, "Stream must be of type IsolatedStorageFileStream".
using( var appStorage = IsolatedStorageFile.GetUserStoreForApplication() )
{
if( appStorage.FileExists( path ) )
{
using( var stream = new XorIsoStoreFileStream( path, FileMode.Open, appStorage ) )
{
App.MainAudioPlayer.SetSource( stream ); // how to put Xor stream here?
}
}
}
Is there something else I can override, like SetSource itself? Doesn't seem like that'd help.
Do I have to implement MediaStreamSource? That seems like huge overkill, reinventing the wheel, etc.
Or is this just not going to work? Will I have to save decrypted parts of the file to a temporary place and SetSource to a normal IsolatedStorageFileStream?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 MediaStreamSource,但这会非常耗时。在您的情况下,在播放之前处理
IsolatedStorageFileStream
实例并将其传递给MediaElement
而不是进行覆盖和传递自定义类会更容易。您将在传递自定义类时遇到问题,因为您需要使用本机
IsolatedStorageFileStream
来通过SetSource
传递它,正如 官方文档。You could use
MediaStreamSource
, but that will be quite time-consuming. It would be much easier in your case to process an instance ofIsolatedStorageFileStream
right before playback and passing it to theMediaElement
instead of having overrides and passing a custom class.You will have problems passing custom classes, since you need to use a native
IsolatedStorageFileStream
to pass it throughSetSource
, as it is stated in the official doc.