3-1. Playing Audio
Problem
You want to listen to music and become entertained with a graphical visualization.
Solution
Create an MP3 player by utilizing the following classes:
javafx.scene.media.Media
javafx.scene.media.MediaPlayer
javafx.scene.media.AudioSpectrumListener
The following source code is an implementation a of simple MP3 player:
package javafx2introbyexample.chapter3.recipe3_01;
import java.io.File;
import java.util.Random;
import javafx.application.*;
import javafx.event.EventHandler;
import javafx.geometry.Point2D;
import javafx.scene.*;
import javafx.scene.input.*;
import javafx.scene.media.*;
import javafx.scene.paint.Color;
import javafx.scene.shape.*;
import javafx.scene.text.Text;
import javafx.stage.*;
/** * Playing ...
Get JavaFX 2.0: Introduction by Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.