Java 3D: How to Play a Sound on Collision and Play or Pause Music on Key Press (with Source Code)

Опубликовано: 16 Апрель 2026
на канале: fukinotou11d
281
2

#Java3Dtutorial #3Dmodel #music
This video explains how to play a crash sound effect when a car collides with a tree, and how to toggle music on and off by pressing the m key.

0:00 Java 3D: How to Play a Sound on Collision and Play or Pause Music on Key Press
1:12 Downloading a Sound Clip
2:16 Editing the .mp3 File and Converting it to a .wav File Using Audacity
3:37 Downloading a MIDI File
4:32 Using AI to Make Music, and Downloading It
7:23 Source Code Explanation
7:44 Playing a Crash Sound Effect on Collision
9:37 Playing or Pausing a MIDI File on Key Press
13:34 Run

Source code described in this video:
https://sites.google.com/view/flying-... (new Google Site)

Source code described in the video,
"Java 3D: How to Detect Collision between an .obj Car Model and Tree Objects_2."
Source Code 1 (simpler version)
Source Code 2 (modified version)
https://sites.google.com/view/flying-... (new Google Site)


Code I referred to for playing sound:
https://www3.ntu.edu.sg/home/ehchua/p...


The SimpleCollision class posted on the Java Tips
https://www.java-tips.org/other-api-t...


Poly was shut down on June 30, 2021. If you need the Poly model I used in this video, you can download it from the link under "3D model file I used".
https://creativecommons.org/licenses/...


3D model file I used:
1) 3D model (A red camaro ZL1 2017) Public / Remixable (CC-BY) (C) by Kris Tong
https://drive.google.com/file/d/1vJnE...


Sound effect file I used:
1) Car Crash Sound Effect (CC BY 4.0) by Spanac Free Sounds Library
https://www.freesoundslibrary.com/car...
License Terms:
https://www.freesoundslibrary.com/car...
https://creativecommons.org/licenses/...


MIDI files I used:

1) Rock (Free Royalty Free Midi Music) (C) by Partners In Rhyme
http://www.partnersinrhyme.com/midi/i...
License Terms:
https://www.partnersinrhyme.com/pir/f...

2) Nothing And The Flowers (computer-generated track #115) (CC BY-SA 4.0) by Computoser
http://computoser.com/
License Terms:
http://computoser.com/
https://creativecommons.org/licenses/...

3) You Ruin Forest (computer-generated track #5789) (CC BY-SA 4.0) by Computoser
http://computoser.com/
License Terms:
http://computoser.com/
https://creativecommons.org/licenses/...


Illustrations (Illust AC) I used:

License Terms:
https://www.ac-illust.com/main/terms.php

1) CD (C) by K-factory Illust AC
https://www.ac-illust.com/main/search...

2) CD player (C) by ayakono Illust AC
https://www.ac-illust.com/main/search...

3) Music notes (C) by こっそり出版 Illust AC
https://www.ac-illust.com/main/search...

4) Play and stop buttons (C) by めめ Illust AC
https://www.ac-illust.com/main/search...

5) Artificial intelligence(C) by 図案屋さん Illust AC
https://www.ac-illust.com/main/search...


Types of licenses
https://en.wikipedia.org/wiki/Creativ...


To learn more:
About Java 3D:

Free online books:
Dr. Andrew Davison's "Killer Game Programming in Java":
https://fivedots.coe.psu.ac.th/~ad/jg
Dr. Andrew Davison's "Pro Java 6 3D Game Development":
https://fivedots.coe.psu.ac.th/~ad/jg2


About Java:
   • Java Programming Tutorial - 2 - Running a ...  
Programming notes:
https://www3.ntu.edu.sg/home/ehchua/p...


To use the KeyNavigatorBehavior class in my Java 3D program (Mykeynavbeh.java), I used the following code;

1) Part of code from BackgroundApp.java included in the source bundle
that accompanies Sun Microsystems' Java 3D API Tutorial
(http://java.sun.com/developer/onlineT...)
Copyright (c) 1996-2000 Sun Microsystems, Inc. All Rights Reserved.

Copy of the above tutorial:
https://web.cs.ucla.edu/classes/cs269...
Change ch0.pdf to ch1.pdf-ch7.pdf in the address bar to display other chapters.

Example source code:
http://www.interactivemesh.org/off/do...


Thank you for watching my video, and I appreciate the people who have posted wonderful free software, images, models, and Java 3D tutorials that allowed me to make this video.