如何使用javafx播放实时音频。 我试过媒体播放器进行音频直播。
http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p这是英国广播公司的无线电流。
但它没有发挥任何作用。谁能帮我? :)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javafxapplication8;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;
/**
*
* @author Top1s
*/
public class JavaFXApplication8 extends Application {
@Override
public void start(Stage stage) {
// Create and set the Scene.
Scene scene = new Scene(new Group(), 540, 209);
stage.setScene(scene);
stage.show();
// Create the media source. The source may be an URI or local file
// for local file
// String source=new File("c:/abc.flv"").toURI().toString());
String source = "http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_p";
// for URI file
// String source="http:/aaa/xyz/abc.flv";
Media media = new Media(source);
// Create the player and set to play automatically.
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
// Create the view and add it to the Scene.
MediaView mediaView = new MediaView(mediaPlayer);
((Group) scene.getRoot()).getChildren().add(mediaView);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}