本文整理匯總了Java中javafx.scene.media.MediaPlayer.setVolume方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setVolume方法的具體用法?Java MediaPlayer.setVolume怎麽用?Java MediaPlayer.setVolume使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.setVolume方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: playCrossfade
import javafx.scene.media.MediaPlayer; //導入方法依賴的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: init
import javafx.scene.media.MediaPlayer; //導入方法依賴的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);
}
示例3: setup
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public void setup(Scene scene)
{
this.scene = scene;
media = new Media(getClass().getResource("video_1.mp4").toExternalForm());
player = new MediaPlayer(media);
mediaView = new MediaView(player);
player.setAutoPlay(true);
player.setVolume(0);
getChildren().add(mediaView);
mediaView.fitWidthProperty().bind(scene.widthProperty());
mediaView.fitHeightProperty().bind(scene.heightProperty());
}
示例4: playBGM
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playBGM(String soundFileName) {
Media sound = new Media(new File(soundFileName).toURI().toString());
try {
bgm = new MediaPlayer(sound);
bgm.setVolume(bgmVolume);
bgm.play();
}catch (MediaException e) {
new CustomAlert(AlertType.ERROR, "Sound Manager Error").show();
}
}
示例5: playSoundEffect
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playSoundEffect(String soundFileName) {
Media sound = new Media(new File(soundFileName).toURI().toString());
try {
MediaPlayer soundEffect = new MediaPlayer(sound);
soundEffect.setVolume(soundEffectVolumn);
soundEffect.play();
soundPlayers.add(soundEffect);
}catch (MediaException e) {
new CustomAlert(AlertType.ERROR, "Sound Manager Error").show();
}
}
示例6: init
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
/**
* Initialisieren des Levels
*
* @param collector - Objektsammler für den LevelLoader
*/
@Override
protected void init(ObjectCollector collector) {
// Initialisieren der Hintergrundmusik
levelTheme = new Media(getClass().getResource("/de/janroslan/verse/resources/sounds/levelTheme.aiff").toExternalForm());
mediaPlayer = new MediaPlayer(levelTheme);
mediaPlayer.setVolume(0.4);
mediaPlayer.setAutoPlay(true);
// Initialisiere Hintergrund
DrawImage bg = new DrawImage("bg", 0, 0, new Image("/de/janroslan/verse/resources/sky.png"), 1.7, 2, 0);
collector.add(bg);
// Init Wände
initWalls(collector);
// Init Türen
ArrayList<BasicNode[]> doors = initDoors(collector);
// Init Schalter
initObjs(collector, doors);
// Spieler initialisieren
player = new Player(100, 210);
collector.registerCollider(player, CollisionType.AABox2D, "wall");
collector.add(player);
// Zeilflagge initialisieren
finish = new LevelFinish(Game.W_WIDTH - 70, Game.W_HEIGHT - 74);
collector.registerCollider(finish, CollisionType.AABox2D, "player");
collector.add(finish);
}
示例7: backMusicStart
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public static void backMusicStart(String path)
{
mp = new MediaPlayer(new Media(ManagerAudio.class.getResource(path).toString())); //Задаём песенку
mp.setCycleCount(MediaPlayer.INDEFINITE); //Цикличность
mp.setVolume(0.5D); //Громкость
mp.setAutoPlay(true); //Автозапуск
mp.play(); //Играем
}
示例8: setVolumeForAllSounds
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
/**
* Sets the volume for all sounds controlled by {@link SuperSoundManager}.
*
* @param volume
* The new volume to set immediately for all controlled sounds.
*/
public static void setVolumeForAllSounds(double volume) {
MediaPlayer[] snapshotOfAllSounds = allControlledSounds.toArray(new MediaPlayer[0]);
for (MediaPlayer sound : snapshotOfAllSounds) {
if (sound.getStatus() != Status.DISPOSED)
sound.setVolume(volume);
}
}
示例9: loadSong
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
public void loadSong() {
media = new Media(file.toURI().toString());
mediaPlayer = new MediaPlayer(getMedia());
mediaPlayer.setVolume(DEFAULT_VOLUME);
}
示例10: Sound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
/**
*creates a Sound object using the file specified by u
* @param u
*/
public Sound(URL u){
mp = new MediaPlayer(new Media(u.toString()));
mp.setVolume(1 * masterVolume);
sl.add(this);
}
示例11: SoundEffectBuilder
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private SoundEffectBuilder(String soundEffectFilename) {
soundEffect = new MediaPlayer(new Media(soundEffectFilename));
soundEffect.setCycleCount(1);
soundEffect.setVolume(masterVolume);
callback = () -> {};
}
示例12: playGunSound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playGunSound(){
MediaPlayer playSoundGun = new MediaPlayer(gunSound);
playSoundGun.setVolume(0.3f);
playSoundGun.play();
}
示例13: playGrenadeSound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playGrenadeSound(){
MediaPlayer playSoundGrenade = new MediaPlayer(grenadeSound);
playSoundGrenade.setVolume(0.3f);
playSoundGrenade.play();
}
示例14: playVictorySound
import javafx.scene.media.MediaPlayer; //導入方法依賴的package包/類
private void playVictorySound(){
MediaPlayer playSoundVictory = new MediaPlayer(victorySound);
playSoundVictory.setVolume(0.3f);
playSoundVictory.play();
}