本文整理了Java中com.badlogic.gdx.Audio.newMusic()
方法的一些代码示例,展示了Audio.newMusic()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Audio.newMusic()
方法的具体详情如下:
包路径:com.badlogic.gdx.Audio
类名称:Audio
方法名:newMusic
[英]Creates a new Music instance which is used to play back a music stream from a file. Currently supported formats are WAV, MP3 and OGG. The Music instance has to be disposed if it is no longer used via the Music#dispose() method. Music instances are automatically paused when ApplicationListener#pause() is called and resumed when ApplicationListener#resume() is called.
[中]创建用于播放文件中音乐流的新音乐实例。目前支持的格式有WAV、MP3和OGG。如果音乐实例不再通过Music#dispose()方法使用,则必须将其释放。音乐实例在调用ApplicationListener#pause()时自动暂停,在调用ApplicationListener#resume()时恢复。
代码示例来源:origin: libgdx/libgdx
@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, MusicParameter parameter) {
music = Gdx.audio.newMusic(file);
}
代码示例来源:origin: libgdx/libgdx
@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, MusicParameter parameter) {
music = Gdx.audio.newMusic(file);
}
代码示例来源:origin: libgdx/libgdx
void setSong (Song song) {
if (music != null) {
music.dispose();
}
switch (song) {
default:
case MP3:
music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.mp3"));
songDuration = 183;
break;
case OGG:
music = Gdx.audio.newMusic(Gdx.files.internal("data/cloudconnected.ogg"));
songDuration = 22;
break;
case WAV:
music = Gdx.audio.newMusic(Gdx.files.internal("data/8.12.loop.wav"));
songDuration = 4;
break;
}
music.setLooping(btLoop.isChecked());
music.play();
}
代码示例来源:origin: libgdx/libgdx
@Override
public void create () {
// copy an internal mp3 to the external storage
FileHandle src = Gdx.files.internal("data/8.12.mp3");
FileHandle dst = Gdx.files.external("8.12.mp3");
src.copyTo(dst);
// create a music instance and start playback
Music music = Gdx.audio.newMusic(dst);
music.play();
}
代码示例来源:origin: com.badlogicgames.gdx/gdx
@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, MusicParameter parameter) {
music = Gdx.audio.newMusic(file);
}
代码示例来源:origin: org.mini2Dx/mini2Dx-core
/**
* Constructor
*
* @param musicFile
* The {@link FileHandle} for the music to be looped
* @param crossfadeTime
* The time (in seconds) at which the crossfade begins at the end
* of the track
* @param crossfadeDuration
* The duration of the crossfade in seconds
*/
public CrossFadingMusicLoop(FileHandle musicFile, float crossfadeTime, float crossfadeDuration) {
this.currentTrack = Gdx.audio.newMusic(musicFile);
this.nextTrack = Gdx.audio.newMusic(musicFile);
this.crossfadeTime = crossfadeTime;
this.crossfadeDuration = crossfadeDuration;
scheduledExecutorService = Executors.newScheduledThreadPool(1);
}
代码示例来源:origin: Mknsri/Drunk-Toss
public static Music loadMusic(String path) {
return Gdx.audio.newMusic(Gdx.files.internal(path));
}
代码示例来源:origin: dingjibang/GDX-RPG
/**播放一个音乐,如果正在播的就是这首音乐,则重新播放*/
public MusicProxy play(String path) {
MusicProxy proxy = null;
if(manager.containsKey(path)){
proxy = manager.get(path);
}else{
proxy = new MusicProxy(Gdx.audio.newMusic(Gdx.files.internal(path)));
manager.put(path, proxy);
}
proxy.music.play();
return proxy;
}
代码示例来源:origin: kbz/SIFTrain
public static Music loadSongByName(String name) {
try {
// try loading the file
FileHandle handle = Gdx.files.absolute(Gdx.files.getExternalStoragePath() + SONGFILE_PREFIX + name);
return Gdx.audio.newMusic(handle);
} catch(Exception e) {
// if it failed, try loading the file with a different extension (in case the extension was not specified)
FileHandle handle = null;
String path = Gdx.files.getExternalStoragePath() + SONGFILE_PREFIX + name.replaceAll("\\.[a-zA-Z0-9]+$","");
for(String ext : SONGFILE_PRIO) {
try {
handle = Gdx.files.absolute(path + ext);
return Gdx.audio.newMusic(handle);
} catch(Exception e2) {
continue;
}
}
return null;
}
}
代码示例来源:origin: com.harium.etyl/etyl-gdx
public Music loadMusic(String path) {
Music music = Gdx.audio.newMusic(Gdx.files.internal((fullPath() + path)));
music.setLooping(true);
return music;
}
代码示例来源:origin: Catacomb-Snatch/Catacomb-Snatch
private void loadMusic(Sounds music) {
try {
Gdx.app.log(TAG, Gdx.files.internal("music/" + music.name + ".ogg").file().getAbsolutePath());
Music file = Gdx.audio.newMusic(Gdx.files.internal("music/" + music.name + ".ogg"));
// If background track, add to playlist
if (music.name.toLowerCase().startsWith("background")) backgroundMusicList.add(file);
musicMap.put(music.name, file);
} catch (GdxRuntimeException e) {
Gdx.app.log(TAG, "Error loading musicfile: " + music.name + ": " + e.getMessage());
}
}
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
@Override
public void run() {
music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(sound));
try {
music.play();
} catch(Exception e) {
// sometimes the play method fails on desktop.
EngineLogger.error("Error Playing music: " + s, e);
}
}
}.start();
代码示例来源:origin: bladecoder/bladecoder-adventure-engine
@Override
public void run() {
music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile));
music.setLooping(true);
music.play();
}
}.start();
代码示例来源:origin: 00-Evan/shattered-pixel-dungeon-gdx
public void play( String assetName, boolean looping ) {
if (isPlaying() && lastPlayed.equals( assetName )) {
return;
}
stop();
lastPlayed = assetName;
lastLooping = looping;
if (!enabled || assetName == null) {
return;
}
player = Gdx.audio.newMusic(Gdx.files.internal(assetName));
player.setLooping(looping);
player.setVolume(volume);
player.play();
}
代码示例来源:origin: dsaltares/libgdx-cookbook
@Override
public void create() {
listener = new SongListener();
songs = new Array<Music>();
songs.add(Gdx.audio.newMusic(Gdx.files.internal("data/music/song_1.mp3")));
songs.add(Gdx.audio.newMusic(Gdx.files.internal("data/music/song_2.mp3")));
songs.add(Gdx.audio.newMusic(Gdx.files.internal("data/music/song_3.mp3")));
songs.add(Gdx.audio.newMusic(Gdx.files.internal("data/music/song_4.mp3")));
songs.add(Gdx.audio.newMusic(Gdx.files.internal("data/music/song_5.mp3")));
currentSongIdx = 0;
volume = 1.0f;
Gdx.input.setInputProcessor(this);
Gdx.app.log("MusicSample", "Instructions");
Gdx.app.log("MusicSample", "- Press right to play the next song");
Gdx.app.log("MusicSample", "- Press left to play the previous song");
Gdx.app.log("MusicSample", "- Press p to pause");
Gdx.app.log("MusicSample", "- Press r to resume");
Gdx.app.log("MusicSample", "- Press up to increase volume");
Gdx.app.log("MusicSample", "- Press down to decrease volume");
playSong(0);
}
代码示例来源:origin: BrentAureli/FlappyDemo
@Override
public void create () {
batch = new SpriteBatch();
gsm = new GameStateManager();
music = Gdx.audio.newMusic(Gdx.files.internal("music.mp3"));
music.setLooping(true);
music.setVolume(0.1f);
music.play();
Gdx.gl.glClearColor(1, 0, 0, 1);
gsm.push(new MenuState(gsm));
}
代码示例来源:origin: konsoletyper/teavm-libgdx
@Override
public void create () {
Array<Controller> controllers = Controllers.getControllers();
if (controllers.size > 0) {
controller = controllers.first();
}
Controllers.addListener(controllerListener);
setScreen(new MainMenu(this));
music = Gdx.audio.newMusic(Gdx.files.getFileHandle("data/8.12.mp3", FileType.Internal));
music.setLooping(true);
music.play();
Gdx.input.setInputProcessor(new InputAdapter() {
@Override
public boolean keyUp (int keycode) {
if (keycode == Keys.ENTER && Gdx.app.getType() == ApplicationType.WebGL) {
if (!Gdx.graphics.isFullscreen()) Gdx.graphics.setDisplayMode(Gdx.graphics.getDisplayModes()[0]);
}
return true;
}
});
fps = new FPSLogger();
}
代码示例来源:origin: danialgoodwin/dev
@Override
public void create () {
dropImage = new Texture(Gdx.files.internal("droplet.png"));
bucketImage = new Texture(Gdx.files.internal("bucket.png"));
dropSound = Gdx.audio.newSound(Gdx.files.internal("drop.wav"));
rainMusic = Gdx.audio.newMusic(Gdx.files.internal("rain.mp3"));
// start the playback of the background music immediately
rainMusic.setLooping(true);
rainMusic.play();
camera = new OrthographicCamera();
camera.setToOrtho(false, 800, 480);
batch = new SpriteBatch();
bucket = new Rectangle();
bucket.x = 800 / 2 - 64 / 2;
bucket.y = 20;
bucket.width = 64;
bucket.height = 64;
raindrops = new Array<Rectangle>();
spawnRaindrop();
}
代码示例来源:origin: langurmonkey/gaiasky
private void playIndex(int i) {
FileHandle f = musicFiles.get(i);
if (currentMusic != null) {
if (currentMusic.isPlaying()) {
currentMusic.stop();
}
currentMusic.dispose();
}
try {
currentMusic = Gdx.audio.newMusic(f);
currentMusic.setVolume(volume);
currentMusic.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(Music music) {
playNextMusic();
}
});
currentMusic.play();
EventManager.instance.post(Events.MUSIC_TRACK_INFO, musicFiles.get(i).name());
logger.info(I18n.bundle.format("gui.music.playing", musicFiles.get(i).name()));
} catch (Exception e) {
logger.error(e);
}
}
代码示例来源:origin: dsaltares/ashley-superjumper
music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
内容来源于网络,如有侵权,请联系作者删除!