有没有办法在我的 Android 应用程序中发出 MIDI 声音?

发布于 2024-11-15 15:52:21 字数 169 浏览 4 评论 0 原文

我正在尝试制作一个可以同时播放不同MIDI 文件的应用程序。这些文件不会流式传输,我想将它们包含在 apk 中。

最多可以同时播放 12 个...Mp3 或两者的组合也是合适的替代品,但目前 midi 是理想的选择。

这有可能吗?预先感谢堆栈溢出天才! :)

-EltMrx

I'm trying to make an app that can play different midi files at the same time. The files would not be streaming and I would like to include them in the apk.

A maximum of 12 would be played at the same time... Mp3 or a combination of both would also be a suitable substitute but for now midi would be ideal.

Is this at all possible? Thanks in advance to the stack-overflow geniuses! :)

-EltMrx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

两个我 2024-11-22 15:52:21

播放单个声音的一种简单方法是使用MediaPlayer。将声音文件放入 /res/raw 文件夹中,然后使用 R 常量调用以下方法,例如 playSound(R.raw.sound_file_name) 其中 playSound< /code> 看起来像这样:

private void playSound(int soundResId) {
        MediaPlayer mp = MediaPlayer.create(context, soundResId);
        if (mp == null) {
            Log.warn("playSound", "Error creating MediaPlayer object to play sound.");
            return;
        }

        mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e("playSound", "Found an error playing media. Error code: " + what);
                mp.release();
                return true;
            }
        });

        mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                mp.release();
            }
        });

        mp.start();
    }

现在,同时播放多个声音有点复杂,但是有一个很好的解决方案 此处

One easy way to play a single sound is to use MediaPlayer. Put your sound files in the /res/raw folder, then call the below method using R constants, e.g. playSound(R.raw.sound_file_name) where playSound looks something like this:

private void playSound(int soundResId) {
        MediaPlayer mp = MediaPlayer.create(context, soundResId);
        if (mp == null) {
            Log.warn("playSound", "Error creating MediaPlayer object to play sound.");
            return;
        }

        mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.e("playSound", "Found an error playing media. Error code: " + what);
                mp.release();
                return true;
            }
        });

        mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
                mp.release();
            }
        });

        mp.start();
    }

Now, playing multiple sounds at the same time is a bit more complex, but there is a good solution here.

牵你手 2024-11-22 15:52:21

正如 @uncheck 所指出的,您可以使用 MP3 标准的 Android MediaPlayer 类,尽管同时播放多个通道有点棘手。

Android 没有内置合成器,因此如果您想通过某种类型的乐器播放纯 MIDI 文件,最好的选择是使用 适用于 Android 的 libpd。之后,您可能可以找到一个PD patch,其中的合成器可以满足您对给定声音的需求你在追赶。

As @uncheck noted, you can use the standard Android MediaPlayer class for MP3, though playing multiple channels at once is a bit tricky.

Android does not have a built-in synthesizer, so if you want to play pure MIDI files through some type of instrument, your best bet would be to use libpd for Android. After that, you can probably find a PD patch with a synth that would fit your needs for the given sound that you're after.

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