简体   繁体   English

从流播放C#FMOD

[英]C# FMOD playing from stream

Can anyone help me on playing a file from a memorystream using FMOD or any other way? 有人可以帮助我使用FMOD或其他方式从内存流中播放文件吗?

So far i have this: 到目前为止,我有这个:
Variables 变量

    private FMOD.System _fmod = null;
    private FMOD.Sound _sound = null;
    private FMOD.Channel _channel = null;

Code

        var file = File.ReadAllBytes("test.ogg");
        //MessageBox.Show("Bytes from file: " + file.Length);

        FMOD.Factory.System_Create(ref _fmod);

        var result = _fmod.init(2, FMOD.INITFLAGS.NORMAL, (IntPtr)null);
        if(result != FMOD.RESULT.OK) ShowError(result);

        var info = new FMOD.CREATESOUNDEXINFO();

        result = _fmod.createStream(file, MODE.CREATESTREAM, ref info,  ref _sound);
        if (result != RESULT.OK) ShowError(result);

Any help would be greatly appreciated 任何帮助将不胜感激

Firstly I highly recommend you take a look at the "loadfrommemory" example that ships with FMOD (it has a C# version too). 首先,我强烈建议您看一下FMOD附带的“ loadfrommemory”示例(它也具有C#版本)。 But to answer your question here: 但是在这里回答您的问题:

  1. You need to populate some members of the FMOD.CREATESOUNDEXINFO structure: 您需要填充FMOD.CREATESOUNDEXINFO结构的一些成员:

    info.cbsize = Marshal.SizeOf(info); info.cbsize = Marshal.SizeOf(info); info.length = file.Length; info.length = file.Length;

  2. You need to tell FMOD you are providing in-memory data with the OPENMEMORY flag: 您需要告诉FMOD您正在使用OPENMEMORY标志提供内存数据:

    result = _fmod.createStream(file, MODE.CREATESTREAM | MODE.OPENMEMORY, ref info, ref _sound); 结果= _fmod.createStream(文件,MODE.CREATESTREAM | MODE.OPENMEMORY,参考信息,参考_sound);

That should be all you need to get going. 那应该是您开始所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM