我有一个继承自 IsolatedStorageFileStream 的名为 XorIsoStoreFileStream 的类,关键是使用这个类,东西是用异或“加密”编写的,当它对它进行异或时,也可以使用这个类读取它。例如:
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?
最佳答案
您可以使用 MediaStreamSource
,但这会非常耗时。在您的情况下,在播放之前处理 IsolatedStorageFileStream
的实例并将其传递给 MediaElement
而不是覆盖并传递自定义类会容易得多。
您将在传递自定义类时遇到问题,因为您需要使用 native IsolatedStorageFileStream
将其传递给 SetSource
,如 in the official doc 所述.
Passing a generic stream to SetSource(System.IO.Stream) is not supported in Silverlight for Windows Phone. However, the IsolatedStorageFileStream class, which derives from Stream, is suppoted on Silverlight for Windows Phone.
关于c# - MediaElement 的 SetSource 使用继承自 IsolatedStorageFileStream 的自定义流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6905381/