当前位置: 首页>>代码示例>>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;未经允许,请勿转载。