English 中文(简体)
• 在《刑法》中宣传一
原标题:Making audio player in Codename One

我正在用“一号法典”为移动打上 j球,并试图利用另一个透镜在框架中形成声器。 我会遇到很多麻烦,主要是利用媒体管理。 该守则是:

package com.example.audio;
import java.io.IOException;
import java.io.InputStream;

import com.codename1.io.FileSystemStorage;
import com.codename1.media.Media;
import com.codename1.media.MediaManager;
import com.codename1.ui.Display;

public class AudioPlayer {
    private Media MEDIA = null;
    public void playAudio(String fileName) {
        try {
            if (MEDIA == null) {
                InputStream is = FileSystemStorage.getInstance().openInputStream(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) {
            ioe.printStackTrace();
        }
    }
}

• 播放视听节目:

public AudioPlayer audioPlayer = new AudioPlayer(); //audio player 

public Game() {
    changeState(sceneNum);
    audioPlayer.playAudio(FileSystemStorage.getInstance().getAppHomePath() + "res/Sounds/fluffingADuck.wav");
...

这是我的 st痕。

java.io.IOException
    at com.codename1.impl.javase.JavaSEPort.createMedia(JavaSEPort.java:9535)
    at com.codename1.ui.Display.createMedia(Display.java:3705)
    at com.codename1.media.MediaManager.createMedia(MediaManager.java:306)
    at com.example.audio.AudioPlayer.playAudio(AudioPlayer.java:16)
    at com.example.myapp.Game.<init>(Game.java:32)
    at com.example.myapp.Game.getGame(Game.java:41)
    at com.example.myapp.MyApp.runApp(MyApp.java:14)
    at com.codename1.system.Lifecycle.start(Lifecycle.java:129)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at com.codename1.impl.javase.Executor$3$2.run(Executor.java:340)
    at com.codename1.ui.Display.executeSerialCall(Display.java:1395)
    at com.codename1.ui.Display.processSerialCalls(Display.java:1379)
    at com.codename1.ui.Display.mainEDTLoop(Display.java:1166)
    at com.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
    at com.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

这里是掌握声音的夹:

我将其中的一件声音转换成第3号,因为我觉得也许会 w1号国家承认的 t,但这不是解决问题。 我用同样的方法为游戏取回图像,并做得当。 如果有人能够把我指向正确方向,或提供任何援助,那就意味着很多。 在方案拟订中,我仍然只是一个灯塔。 这里指的是,如果任何人想也去看:

问题回答

It seems you re confusing FileSystemStorage with resources. Those are separate concepts. Resources like your sounds, get packaged into your application as part of the final bundle (e.g. jar) and are available to you on the device using an API to fetch the resources.

FileSystemStorage accesses the file system available on the device. Here you first need to write or create the file in some way in order for it to be available for you.

还有其他问题:

  • 你们的资源处于等级。 由于某些包装系统(iOS)的操作有点不同,因此,这没有得到第1号法典的支持。 因此,你可以 files取档案,需要将其全部放在一个目录上。

  • 您指定名录res而不是resources

  • 需在<代码>java和<代码>cs下填写。

为澄清,文件fluffingADuck.wav 须在以下代码上填写common/src/main/resources/fluffingADuck.wav

现在,你们需要制定守则,以使用实际上很简单的资源:

audioPlayer.playAudio("/fluffingADuck.wav");

通知:<代码>/。 它是蓄意的。

然后,你们都需要做的是修改<代码>。 InputStream line to:

InputStream is = CN.getResourceAsStream(fileName);




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签