本文整理汇总了Java中javafx.scene.media.Media类的典型用法代码示例。如果您正苦于以下问题:Java Media类的具体用法?Java Media怎么用?Java Media使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Media类属于javafx.scene.media包,在下文中一共展示了Media类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playCrossfade
import javafx.scene.media.Media; //导入依赖的package包/类
private void playCrossfade(final List<? extends Playable> items, final int index) {
MediaPlayer oldPlayer = currentPlayer;
final double currentVolume = oldPlayer.getVolume();
oldPlayer.volumeProperty().unbind();
playQueue = new ArrayList<>(items);
currentIndex = index;
MediaPlayer newPlayer = new MediaPlayer(new Media(playQueue.get(currentIndex).getUri().toString()));
newPlayer.setVolume(0);
newPlayer.play();
Timeline crossfade = new Timeline(new KeyFrame(Duration.seconds(CROSSFADE_DURATION),
new KeyValue(oldPlayer.volumeProperty(), 0),
new KeyValue(newPlayer.volumeProperty(), currentVolume)));
crossfade.setOnFinished(event -> {
oldPlayer.stop();
setCurrentPlayer(newPlayer);
});
crossfade.play();
}
示例2: addBackgroundMediaView
import javafx.scene.media.Media; //导入依赖的package包/类
private void addBackgroundMediaView() {
Media media = new Media(MovieView.class.getResource("/backdrop-video.mp4").toExternalForm());
MediaPlayer player = new MediaPlayer(media);
player.setMute(true);
MediaView mediaView = new MediaView(player);
mediaView.setOpacity(.3);
getChildren().add(mediaView);
mediaView.visibleProperty().bind(getSkinnable().showMediaViewBackgroundProperty());
getSkinnable().showMediaViewBackgroundProperty().addListener(it -> {
if (getSkinnable().isShowMediaViewBackground()) {
/*
* Implementing our own infinite loop support.
* The built-in cycle count support seems to be buggy.
*/
player.setOnEndOfMedia(() -> {
player.seek(Duration.ZERO);
player.play();
});
player.play();
} else {
player.stop();
}
});
}
示例3: init
import javafx.scene.media.Media; //导入依赖的package包/类
/**
* Level initialisieren
*
* @param collector - Objektsammler
*/
@Override
protected void init(ObjectCollector collector) {
rdm = new Random();
// Init Hintergrundmusik
menuTheme = new Media(getClass().getResource("/de/janroslan/verse/resources/sounds/menu.aiff").toExternalForm());
mplayer = new MediaPlayer(menuTheme);
mplayer.setVolume(0.7);
mplayer.setAutoPlay(true);
// Init Maus Hover Sound
buttonHoverSound = new AudioClip(getClass().getResource("/de/janroslan/verse/resources/sounds/click.wav").toString());
initPictures(collector);
initObjs(collector);
initTexts(collector);
initButtons(collector);
}
示例4: start
import javafx.scene.media.Media; //导入依赖的package包/类
public void start(Stage primaryStage) {
primaryStage.setTitle("Embedded Media Player");
Group root = new Group();
Scene scene = new Scene(root, 540, 241);
// create media player
Media media = new Media("D:\\Pradeep\\Funny Mails\\Magic Sand.wmv");
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setAutoPlay(true);
StackPane stack = new StackPane();
Text t = new Text("Subtitle..");
// t.textProperty().addChangeListener(..);
// MediaControl mediaControl = new MediaControl(mediaPlayer);
MediaView m =new MediaView(mediaPlayer);
stack.getChildren().addAll(m, t);
scene.setRoot(stack);
primaryStage.setScene(scene);
primaryStage.show();
}
示例5: start
import javafx.scene.media.Media; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("JavaFX Video");
final List<String> args = getParameters().getRaw();
String url = args.size() > 0 ?
args.get(args.size() - 1) :
"http://www.mediacollege.com/" +
"video-gallery/testclips/20051210-w50s.flv";
Media media = new Media(url);
MediaPlayer player = new MediaPlayer(media);
player.play();
MediaView view = new MediaView(player);
Group root = new Group();
root.getChildren().add(view);
Scene scene = SceneBuilder.create().
width(360).height(288).
root(root).
fill(Color.WHITE).
build();
primaryStage.setScene(scene);
primaryStage.show();
}
示例6: Music
import javafx.scene.media.Media; //导入依赖的package包/类
public Music(File f)
{
file = f;
String path = StringUtil.convertToFileURL(file.toURI().getRawPath());
String url = StringUtil.convertToFileURL(file.getAbsolutePath());
String[] split = url.split("/");
String uri = url.split("/")[split.length - 1];
String[] sp = uri.split("\\.");
format = new SimpleStringProperty(sp[sp.length - 1]);
sp[sp.length - 1] = "";
name = new SimpleStringProperty(String.join(".", sp));
media = new MediaPlayer(new Media(path));
duration = new SimpleStringProperty("");
}
示例7: run
import javafx.scene.media.Media; //导入依赖的package包/类
@Override
public void run(Queue queue) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Media m = new Media(new File(config.getToneBeforeDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play before download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
示例8: run
import javafx.scene.media.Media; //导入依赖的package包/类
@Override
public void run(Queue queue) {
Thread thread = new Thread(new Runnable() {
public void run() {
try {
Media m = new Media(new File(config.getToneAfterDownloadPath()).toURI().toString());
MediaPlayer mp = new MediaPlayer(m);
mp.play();
} catch (Exception e) {
e.printStackTrace();
DumpManager.getInstance().addDump(new DebugDump(null, "---", "Play after download sound", "---", "Error occurred when trying to play sound", false, e));
}
}
});
thread.setDaemon(true);
thread.start();
}
示例9: playSound
import javafx.scene.media.Media; //导入依赖的package包/类
public static void playSound(String ressource) {
log.info("Try to play " + ressource);
URL url = ClassLoader.getSystemResource(ressource);
String path = null;
if (url == null) {
path = new File(ressource).toURI().toString();
} else
path = url.toString();
log.info("path " + path);
try {
Media media = new Media(path);
MediaPlayer mp = new MediaPlayer(media);
mp.play();
} catch (Exception e) {
log.error("Exception", e);
}
}
示例10: setCurrentPlayer
import javafx.scene.media.Media; //导入依赖的package包/类
private void setCurrentPlayer(final MediaPlayer player) {
currentPlayer = player;
Category newItem = playQueue.get(currentIndex);
switch (CategoryType.of(newItem)) {
case Songs: newSongBeingPlayed(); break;
case Videos: newVideoBeingPlayed(); break;
}
currentPlayer.setOnEndOfMedia(() -> {
if (lastPlayed.size() > maxDeckSize) {
lastPlayed.pollLast();
lastPlayed.addFirst(playQueue.get(currentIndex));
}
currentIndex = nextIndex();
Media media = new Media(playQueue.get(currentIndex).getUri().toString());
setCurrentPlayer(new MediaPlayer(media));
currentPlayer.play();
});
currentPlayer.statusProperty()
.addListener((observable, oldValue, newValue) -> playingStatusChanged(newValue));
currentPlayer.currentTimeProperty().addListener(ov -> timeUpdated());
currentPlayer.currentTimeProperty().addListener(crossfadeTimeListener());
currentPlayer.setOnReady(this::timeUpdated);
currentPlayer.volumeProperty().bind(volume);
}
示例11: playTrailer
import javafx.scene.media.Media; //导入依赖的package包/类
private void playTrailer() {
final Media media = model.getSelectedMovie().loadTrailer();
final MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.setOnEndOfMedia(() -> {
mediaPane.setVisible(false);
mediaPlayer.stop();
mediaPlayer.dispose();
});
mediaView.setOnMouseClicked(e -> {
if(MediaPlayer.Status.PLAYING.equals(mediaPlayer.getStatus())) {
mediaPlayer.pause();
mediaStateIcon.toPlay();
} else {
mediaPlayer.play();
mediaStateIcon.toPause();
}
});
mediaView.setMediaPlayer(mediaPlayer);
mediaPane.setVisible(true);
mediaPlayer.play();
}
示例12: start
import javafx.scene.media.Media; //导入依赖的package包/类
@Override
public void start(Stage stage) {
ScreensController mainContainer = new ScreensController();
mainContainer.loadScreen(screenMenuID, screenMenuFile);
mainContainer.loadScreen(screenMainID, screenMainFile);
mainContainer.setScreen(screenMenuID);
Group root = new Group();
root.getChildren().addAll(mainContainer);
Scene scene = new Scene(root, Color.TRANSPARENT);
stage.setScene(scene);
stage.show();
//Music Theme Himalya
File filestring = new File("src/resources/music/music_menu.mp3");
Media file = new Media(filestring.toURI().toString());
MediaPlayer mediaPlayer = new MediaPlayer(file);
mediaPlayer.autoPlayProperty();
mediaPlayer.setCycleCount(MediaPlayer.INDEFINITE);
mediaPlayer.play();
}
示例13: Game
import javafx.scene.media.Media; //导入依赖的package包/类
/**
* Instantiates a new model.Game.
* <p>
* Init szekvencia.
* </p>
*/
public Game() {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("game.fxml"));
Parent root = null;
try {
root = fxmlLoader.load();
} catch (IOException e) {
e.printStackTrace();
return;
}
Controller ctrl = fxmlLoader.getController();
ctrl.setModel(this);
timer = new SimulationTimer();
mapManager = new MapManager(timer, this);
view = new View(mapManager, ctrl);
view.setScene(new Scene(root));
timer.setView(view);
winMedia = new MediaPlayer(new Media(new File(winSound).toURI().toString()));
loseMedia = new MediaPlayer(new Media(new File(loseSound).toURI().toString()));
}
示例14: loadingParam
import javafx.scene.media.Media; //导入依赖的package包/类
private void loadingParam() {
File paramFile = new File("res/Parameters");
Scanner sc;
try {
sc = new Scanner(paramFile);
if (sc.hasNextLine()) {
isRandom = Boolean.valueOf(sc.nextLine());
musicIndex = Integer.valueOf(sc.nextLine());
}
hit = new Media(musicList.get(musicIndex).toURI().toString());
mediaPlayer = new MediaPlayer(hit);
mediaPlayer.setOnReady(this::playMusic);
} catch (IOException e) {
e.printStackTrace();
}
}
示例15: loadingFile
import javafx.scene.media.Media; //导入依赖的package包/类
private boolean loadingFile() {
File f = new File("res/MusicList");
Scanner scn;
try {
scn = new Scanner(f);
if (!scn.hasNextLine()) return false;
while (scn.hasNextLine()) {
musicList.add(new File(scn.nextLine()));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
for (int i = 0; i < musicList.size(); i++) {
Media hit = new Media(musicList.get(i).toURI().toString());
String song = hit.getSource().split("/")[hit.getSource().split("/").length - 1].replace("%20", " ");
listView.getItems().add(song);
}
listView.scrollTo(0);
return true;
}