c# - MediaElement 的 SetSource 使用继承自 IsolatedStorageFileStream 的自定义流

标签 c# silverlight windows-phone-7 stream mediaelement

我有一个继承自 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/

相关文章:

silverlight - 我可以在我的应用程序中反转手机屏幕的颜色吗?

c# - Windows Phone 7.1 "Send To"功能?

c# - 使用 Lightswitch、Silverlight 和自定义控件

c# - 使用 GO 批处理分隔符执行 SQL 脚本并读取结果

c# - 如何使 CefSharp WinForms 控件滚动页面到链接

c# - MongoDB ssl 通过 C# 驱动程序 : The remote certificate is invalid according to the validation procedure

windows-phone-7 - ListBox ItemsSource 绑定(bind)通过代码而不是通过 XAML

c# - Using block 中的异步

windows-phone-7 - Windows Phone 7 麦克风可以检测 18k-19kHz 范围内的频率吗?

c# - 为什么绑定(bind)的 StringFormat 不使用当前区域性?