如何将声音与Codename One捆绑在一起?

编程入门 行业动态 更新时间:2024-10-08 13:37:37
本文介绍了如何将声音与Codename One捆绑在一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的Codename One应用程序中包含声音,以实现诸如单击按钮,过渡等效果.我不希望从URL下载声音,因为它们很小,并且我希望即使在设备处于播放状态时也可以播放声音未连接到互联网.看来我无法在主题中包含源文件.我该怎么办?

I want to include sounds in my Codename One app for effects like clicking a button, transitions, etc. I prefer not to download them from URL, since they are very small and I want them to be played even when the device is not connected to the internet. It looks like I cannot include the source files in the theme. What should I do?

推荐答案

将声音文件放入项目文件夹中的"src"文件夹,并按如下所示进行引用:

Put the sound file in the "src" folder inside your project folder and reference it like below:

private Media MEDIA = null; public void playAudio(String fileName) { try { if (MEDIA == null) { final InputStream is = Display.getInstance().getResourceAsStream(getClass(), "/" + fileName); MEDIA = MediaManager.createMedia(is, "audio/mp3", new Runnable() { @Override public void run() { MEDIA = null; } }); } if (MEDIA != null && MEDIA.isPlaying() == false) { MEDIA.setVolume(100); MEDIA.play(); } } catch (IOException ioe) { } } ... playAudio("my_sound.mp3");

更多推荐

如何将声音与Codename One捆绑在一起?

本文发布于:2023-11-23 22:11:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622997.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   声音   Codename

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!