11/*
2- * Copyright (c) 2009-2019 jMonkeyEngine
2+ * Copyright (c) 2009-2026 jMonkeyEngine
33 * All rights reserved.
44 *
55 * Redistribution and use in source and binary forms, with or without
@@ -142,6 +142,20 @@ public SoundEvent(String path, float initialDuration, LoopMode loopMode) {
142142 this .path = path ;
143143 }
144144
145+ /**
146+ * Creates a sound event using the specified {@link AudioNode}.
147+ * <p>
148+ * This constructor is useful when the audio has already been loaded or
149+ * preconfigured, allowing the event to play an existing {@code AudioNode}
150+ * without relying on path‑based loading.
151+ * </p>
152+ *
153+ * @param audioNode the audio node to be played by this event (not null)
154+ */
155+ public SoundEvent (AudioNode audioNode ) {
156+ this .audioNode = audioNode ;
157+ }
158+
145159 /**
146160 * creates a sound event
147161 * used for serialization
@@ -153,10 +167,11 @@ public SoundEvent() {
153167 @ Override
154168 public void initEvent (CinematicHandler cinematic ) {
155169 super .initEvent (cinematic );
156- audioNode = new AudioNode (cinematic .getAssetManager (), path ,
157- stream ? AudioData .DataType .Stream : AudioData .DataType .Buffer );
158- audioNode .setPositional (false );
159- setLoopMode (loopMode );
170+ if (audioNode == null ) {
171+ audioNode = new AudioNode (app .getAssetManager (), path , stream ? AudioData .DataType .Stream : AudioData .DataType .Buffer );
172+ audioNode .setPositional (false );
173+ setLoopMode (loopMode );
174+ }
160175 }
161176
162177 @ Override
@@ -229,3 +244,4 @@ public void read(JmeImporter im) throws IOException {
229244 audioNode = (AudioNode ) ic .readSavable ("audioNode" , null );
230245 }
231246}
247+
0 commit comments