English 中文(简体)
PulpCore music playback - loop sound and animate volume
原标题:

I have been experimenting with PulpCore, trying to create my own tower defence game (not-playable yet), and I am enjoying it very much I ran into a problem that I can t quite figure out. I extended PulpCore with the JOrbis thing to allow OGG files to be played. Works fine. However, pulpCore seems to have a problem with looping the sound WHILE animating the volume level. I tried this with wav file too, to make sure it isn t jOrbis that breaks it. The code is like this:

Sound bgMusic = Sound.load("music/music.ogg");
Playback musicPlayback;
...

musicVolume = new Fixed(0.75);
musicPlayback = bgMusic.loop(musicVolume);
//TODO figure out why it s NOT looping when volume is animated
//  musicVolume.animate(0, musicVolume.get(), FADE_IN_TIME);

This code, for as long as the last line is commented out, plays the music.ogg again and again in an endless loop (which I can stop by calling stop on the Playback object returned from loop(). However, I would like the music to fade in smoothly, so following the advice of the PulpCore API docs, I added the last line which will create the fade-in but the music will only play once and then stop. I wonder why is that? Here is a bit of the documentation:

Playback pulpcore.sound.Sound.loop(Fixed level)

Loops this sound clip with the specified volume level (0.0 to 1.0). The level may have a property animation attached.

Parameters: level

Returns: a Playback object for this unique sound playback (one Sound can have many simultaneous Playback objects) or null if the sound could not be played.

So what could be the problem? I repeat, with the last line, the sound fades in but doesn t loop, without it it loops but starts with the specified 0.75 volume level. Why can t I animate the volume of the looped music playback? What am I doing wrong? Anyone has any experience with pulpCore and has come across this problem? Anyone could please download PulpCore and try to loop music which fades-in (out)?

note: I need to keep a reference to the Playback object returned so I can kill music later.

最佳回答

Finally I managed to get an explanation and a simple work-around for this issue from the pulp core author. So here it is:

It is a PulpCore bug. When the output volume is zero, the sound player stops looping the sound.

To work around it, animate from a value that is not zero, like this:

musicVolume.animate(0.0001, 1, FADE_IN_TIME); 

Link to this on pulpcore Google groups

问题回答

If the animate method only sets the option, it can work unpredictably - try switching this line with the loop itself, so the animation applies first.

Can you animate the volume on an unlooped playback, and then, at the end of that playback, start the loop at the fixed level?





相关问题
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 ...

热门标签