當前位置: 首頁>>代碼示例>>Java>>正文


Java Media類代碼示例

本文整理匯總了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();
}
 
開發者ID:jakemanning,項目名稱:boomer-tuner,代碼行數:20,代碼來源:Player.java

示例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();
        }
    });
}
 
開發者ID:hendrikebbers,項目名稱:ExtremeGuiMakeover,代碼行數:26,代碼來源:MovieViewSkin.java

示例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);
    

}
 
開發者ID:Jackjan4,項目名稱:Verse,代碼行數:27,代碼來源:MainMenu.java

示例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();
}
 
開發者ID:SaiPradeepDandem,項目名稱:javafx-demos,代碼行數:23,代碼來源:MediaPlayerDemo.java

示例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();
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:26,代碼來源:JfxVideo.java

示例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("");
    
    
}
 
開發者ID:Aruisehu,項目名稱:SupPlayer,代碼行數:18,代碼來源:Music.java

示例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();
}
 
開發者ID:mob41,項目名稱:osumer,代碼行數:18,代碼來源:BeforeSoundAction.java

示例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();
}
 
開發者ID:mob41,項目名稱:osumer,代碼行數:18,代碼來源:AfterSoundAction.java

示例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);
        }
    }
 
開發者ID:schwabdidier,項目名稱:GazePlay,代碼行數:24,代碼來源:Utils.java

示例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);
}
 
開發者ID:jakemanning,項目名稱:boomer-tuner,代碼行數:27,代碼來源:Player.java

示例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();
}
 
開發者ID:hendrikebbers,項目名稱:ExtremeGuiMakeover,代碼行數:22,代碼來源:MasterDetailViewController.java

示例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();
}
 
開發者ID:sebastienscout,項目名稱:Himalaya-JavaFX,代碼行數:23,代碼來源:Main.java

示例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()));
}
 
開發者ID:AdjustmentBeaver,項目名稱:szoftlab,代碼行數:26,代碼來源:Game.java

示例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();
    }
}
 
開發者ID:oussamabonnor1,項目名稱:Music_Player_material_design_javaFX,代碼行數:17,代碼來源:Main.java

示例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;
}
 
開發者ID:oussamabonnor1,項目名稱:Music_Player_material_design_javaFX,代碼行數:22,代碼來源:Main.java


注:本文中的javafx.scene.media.Media類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。