Integration into other software

For integrating SoundHelix into a third-party Java software, you can use the SoundHelix API for generating and playing songs. For this, you must add SoundHelix.jar and log4j.jar to your classpath (or provide your own version of log4j). Then, use the com.soundhelix.util.SongUtils class provided by SoundHelix to generate a song and get a SongContext instance which you can use for playing the song. Internally, this will generate a song name by using a SongNameEngine instance (which will be skipped if you provide a song name instead of a random seed) and will then generate a harmony by using a HarmonyEngine instance, will then generate an Arrangement by using an ArrangementEngine instance and will then generate a Player instance.

The following simple quick-and-dirty Java code will load a SoundHelix XML file, generate a song and play it. Note that this will not give you any remote-controlling capabilities (i.e., no ConsoleRemoteControl for entering commands).

import org.apache.log4j.PropertyConfigurator;
import com.soundhelix.component.player.Player;
import com.soundhelix.misc.SongContext;
import com.soundhelix.util.SongUtils;

public class SoundHelixTest {
    public static void main(String[] args) {
        try {
            // configure log4j
            PropertyConfigurator.configureAndWatch("", 60 * 1000);

            SongContext songContext = SongUtils.generateSong(new URL(""),
            // use this instead to generate a specific song based on the given song name
            // SongContext songContext = SongUtils.generateSong(new URL(""),
            //                                                  "My song name");
            Player player = songContext.getPlayer();
        } catch (Exception e) {

URLs can also be used to load files from your local computer or to directly provide XML content as a string.

Of course, you can also create a separate thread which does the playback. For remote-controlling the player during playback, just look at the methods provided by the Player class.

Please have a look at the license for details about integrating SoundHelix into your software.

Add new comment