String bip = "bip.mp3"; Media hit = new Media(bip); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play();
import javafx.application.Application; import javafx.scene.*; import javafx.scene.media.*; import javafx.stage.Stage; public class VideoPlayerExample extends Application { public static void main(String[] args) throws Exception { launch(args); } @Override public void start(final Stage stage) throws Exception { final MediaPlayer oracleVid = new MediaPlayer( new Media("http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv") ); stage.setScene(new Scene(new Group(new MediaView(oracleVid)), 540, 208)); stage.show(); oracleVid.play(); } }
MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play(); // never do this: //Thread.sleep(10000); PauseTransition pause = new PauseTransition(Duration.millis(10000)); pause.setOnFinished(e -> { System.out.println("Fade"); }); pause.play();
MediaPlayer mediaPlayer public void music(){ String bip = "src/data/fjordmusic.mp3"; Media hit = new Media(Paths.get(bip).toUri().toString()); mediaPlayer = new MediaPlayer(hit); mediaPlayer.play(); }
Media m = new Media(Paths.get("example.flv").toURI().toString()); MediaPlayer mp = new MediaPlayer(m); MediaView mv = new MediaView(mp); // Add the mediaview component somewhere to your GUI // And you're done. You can start playing the video by: mp.play();
Media hit = new Media(getClass().getResource(bip).toExternalForm()); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play();
public class Test extends javafx.application.Application { @Override public void start(Stage primaryStage) throws Exception { File file = new File("/path/test.mp3"); Media media = new Media(file.toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.play(); } }
public class Reproductor extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage) throws Exception { Media media = new Media("file:///Movies/test.mp3"); //replace /Movies/test.mp3 with your file MediaPlayer player = new MediaPlayer(media); player.play(); } }
private static void playSound(String sound){ // cl is the ClassLoader for the current class, ie. CurrentClass.class.getClassLoader(); URL file = cl.getResource(sound); final Media media = new Media(file.toString()); final MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.play(); }
import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; public class Utils { public static void playSound(String fileName){ Media m = new Media("file:///" + System.getProperty("user.dir").replace('\\', '/') + "/" + fileName); MediaPlayer player = new MediaPlayer(m); player.play(); } }
private void nextMedia(){ MediaPlayer player=playList.get(currentMediaIndex++); attachListeners(player); if(player!=null){ player.play(); } else { nextMedia(); } }
String mysound = "sound.mp3"; Media hit = new Media(mysound); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play();
Media hit = new Media(new File(bip).toURI().toURL().toString()); MediaPlayer mediaPlayer = new MediaPlayer(hit); mediaPlayer.play();
String musicFile = "StayTheNight.mp3"; // For example Media sound = new Media(new File(musicFile).toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(sound); mediaPlayer.play();
public static void playAudio(String name, double startMillis, double stopMillis) { Media media = new Media(Paths.get(name).toUri().toString()); MediaPlayer player = new MediaPlayer(media); player.setStartTime(new Duration(startMillis)); player.setStopTime(new Duration(stopMillis)); player.play(); }
private void playMedia(Media m){ if (m != null){ MediaPlayer mp = new MediaPlayer(m); mp.play(); } } public void playSomeSound(){ try{ Media someSound = new Media(getClass().getResource("some-sound.mp3").toString()); playMedia(someSound); }catch(Exception ex){ GeeLogger.error(getClass(), ex.getLocalizedMessage(), ex); } }
String fileName=null; JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "MP3 Files", "mp3"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(parent); if(returnVal == JFileChooser.APPROVE_OPTION) { fileName= chooser.getSelectedFile().getName(); } MediaPlayer mediaPlayer = new MediaPlayer(new Media(fileName)); mediaPlayer.play();
@FXML private Button button; @FXML private MediaPlayer mediaPlayer; @Override public void initialize(URL url, ResourceBundle rb) { mediaPlayer.setOnEndOfMedia(()->button.setVisible(true)); } @FXML public void playAndHide(ActionEvent event){ button.setVisible(false); mediaPlayer.seek(Duration.ZERO); mediaPlayer.play(); }
@Override public void actionPerformed(ActionEvent e) { if (!mediaPlayer.isPlaying()) { mediaPlayer.play(); } else { mediaPlayer.pause(); } } }