MediaElement 的 SetSource 使用继承自isolatedStorageFileStream 的自定义流

发布于 2024-11-27 09:52:08 字数 1124 浏览 0 评论 0原文

我有一个名为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

裸钻 2024-12-04 09:52:08

您可以使用 MediaStreamSource,但这会非常耗时。在您的情况下,在播放之前处理 IsolatedStorageFileStream 实例并将其传递给 MediaElement 而不是进行覆盖和传递自定义类会更容易。

您将在传递自定义类时遇到问题,因为您需要使用本机 IsolatedStorageFileStream 来通过 SetSource 传递它,正如 官方文档

将通用流传递给 SetSource(System.IO.Stream) 不是
Windows Phone 版 Silverlight 受支持。然而,
isolatedStorageFileStream 类,派生自 Stream,是
Silverlight for Windows Phone 支持。

You could use MediaStreamSource, but that will be quite time-consuming. It would be much easier in your case to process an instance of IsolatedStorageFileStream right before playback and passing it to the MediaElement 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 through SetSource, as it is stated 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文