java - How to play sounds with JavaFX -
I just started working with JavaFX. I know how its basics work. I "sound.m.pe." Tried to use media and intermediate sections to play a sound called. I am programming in eclipse, and I have a sound file in the src folder, "folder (like the default package)" is my code here:
Import javafx.scene.media. *; Import javafx.application.Application; Import javafx.scene.Scene; Import javafx.scene.layout.StackPane; Import javafx.stage.Stage; Public class man application {public static expands zero main (string [] args) {launch (args); } @ Override Public Voic Rate (Stage Primary Stage) {Primary Stage .Cetital ("Hello World!"); String ssound = "sound.mp3"; Media sound = new media (ssound); Media Player Mediaplayer = new media player (sound); mediaPlayer.play (); Stackpan root = new stackpan (); primaryStage.setScene (new view (root, 800, 450)); PrimaryStage.show (); }} Please tell me what I am doing.
Here's the error message from the console:
Thread "main" exception in the application start method exception in java.lang.RuntimeException: com.sun.javafx.application Exception in application launch method on LauncherImpl.launchApplication .com.sun.javafx.application.LauncherImpl.access (unknown source) $ 000 (unknown source) com.sun.javafx.application.LauncherImpl $ 1.run (unknown source) Reason: java.lang.IllegalArgumentException: uri.getScheme () == Tap on java.lang.Thread.run (Thread.Java: 724) Com.sun.media.jfxmedia.locator.locator at javafx.scene.media.media. & Lt; Init & gt; (Unknown source) & lt; Init & gt; (Unknown source) com.sun.javafx.application.LauncherImpl $ 5.run at main.start (main.java16) com.sun.javafx.application.PlatformImpl $ 5.run (unknown source) com .sun.javafx.application.PlatformImpl $ 4 $ 1.Run (unknown source) com.sun.javafx.application.PlatformImpl $ 4 $ 1.Run (unknown source) java.security.AccessController.doPrivileged (basic method) com .sun.javafx.application.PlatformImpl $ 4.run at (unknown source) at com.un.glass.ui.InvokeLaterDispatcher $ Future.Run (unknown source) com.sun.glass.ui.win.WinApplication._runLoop (at Basic method) com.sun.glass.ui.win.WinApplication.access $ 100 (unknown source) com.sun.glass.ui.win.WinApplication $ 3 $ 1.run (unknown source) ... 1 more < / code>
What is the only compilation of other responses:
string music file = "live mp3. 3 "; // Media Sound for example = new media (new file (music file) .toURI () .toString ()); Media Player Mediaplayer = new media player (sound); mediaPlayer.play (); Add a music file to your project folder along with and src . Any IDE will indicate that you can also add:
import javafx.scene.media.Media; Import javafx.scene.media.MediaPlayer; Import java.io.file; works like a charm
जावा प्रोग्रामिंग नमूना कोड
ReplyDeleteमूल दिनांक स्वरूपण कोड उदाहरण