com.badlogic.gdx.Audio类的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(189)

本文整理了Java中com.badlogic.gdx.Audio类的一些代码示例,展示了Audio类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Audio类的具体详情如下:
包路径:com.badlogic.gdx.Audio
类名称:Audio

Audio介绍

[英]This interface encapsulates the creation and management of audio resources. It allows you to get direct access to the audio hardware via the AudioDevice and AudioRecorder interfaces, create sound effects via the Sound interface and play music streams via the Music interface.

All resources created via this interface have to be disposed as soon as they are no longer used.

Note that all Music instances will be automatically paused when the ApplicationListener#pause() method is called, and automatically resumed when the ApplicationListener#resume() method is called.
[中]此接口封装了音频资源的创建和管理。它允许您通过音频设备和录音机接口直接访问音频硬件,通过声音接口创建声音效果,并通过音乐接口播放音乐流。
通过此接口创建的所有资源在不再使用时必须立即进行处置。
请注意,调用ApplicationListener#pause()方法时,所有音乐实例都将自动暂停,调用ApplicationListener#resume()方法时,所有音乐实例将自动恢复。

代码示例

代码示例来源:origin: libgdx/libgdx

@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, SoundParameter parameter) {
  sound = Gdx.audio.newSound(file);
}

代码示例来源: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 resume () {
    device = Gdx.audio.newAudioDevice(44100, true);
    recorder = Gdx.audio.newAudioRecorder(44100, true);
  }
}

代码示例来源: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: libgdx/libgdx

@Override
public void create () {
  if (thread == null) {
    final AudioDevice device = Gdx.app.getAudio().newAudioDevice(44100, false);
    thread = new Thread(new Runnable() {
      @Override
      public void run () {
        final float frequency = 440;
        float increment = (float)(2 * Math.PI) * frequency / 44100; // angular increment for each sample
        float angle = 0;
        float samples[] = new float[1024];
        while (!stop) {
          for (int i = 0; i < samples.length; i += 2) {
            samples[i] = 0.5f * (float)Math.sin(angle);
            samples[i + 1] = 2 * samples[i];
            angle += increment;
          }
          device.writeSamples(samples, 0, samples.length);
        }
        device.dispose();
      }
    });
    thread.start();
  }
}

代码示例来源:origin: dsaltares/ashley-superjumper

music = Gdx.audio.newMusic(Gdx.files.internal("data/music.mp3"));
music.setLooping(true);
music.setVolume(0.5f);
if (Settings.soundEnabled) music.play();
jumpSound = Gdx.audio.newSound(Gdx.files.internal("data/jump.wav"));
highJumpSound = Gdx.audio.newSound(Gdx.files.internal("data/highjump.wav"));
hitSound = Gdx.audio.newSound(Gdx.files.internal("data/hit.wav"));
coinSound = Gdx.audio.newSound(Gdx.files.internal("data/coin.wav"));
clickSound = Gdx.audio.newSound(Gdx.files.internal("data/click.wav"));

代码示例来源:origin: tube42/drumon

public void open()
{
  if(ad != null) {
    close();
  }
  System.out.println("DEVICE OUTPUT: opening...");
  int freq = World.freq;
  ad = Gdx.audio.newAudioDevice(freq, true);
  int lat = ad.getLatency();
  System.out.println(
       "AudioDevice latency=" + lat + "samp/" +
       (1000 * lat / (float)freq) + " ms " +
       " freq=" + freq +
       " mono=" + ad.isMono()
       );
}

代码示例来源:origin: libgdx/libgdx

@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, SoundParameter parameter) {
  sound = Gdx.audio.newSound(file);
}

代码示例来源: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 create () {
  device = Gdx.audio.newAudioDevice(44100, true);
  recorder = Gdx.audio.newAudioRecorder(44100, true);
  Thread t = new Thread(new Runnable() {
    @Override
    public void run () {
      while (true) {
        recorder.read(samples, 0, samples.length);
        device.writeSamples(samples, 0, samples.length);
      }
    }
  });
  t.setDaemon(true);
  t.start();
}

代码示例来源:origin: libgdx/libgdx

@Override
public void create () {
  Gdx.audio.newSound(Gdx.files.internal("data/tic.ogg")).play();
}

代码示例来源: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 () {
  sound = Gdx.audio.newSound(Gdx.files.getFileHandle("data/shotgun.ogg", FileType.Internal));

代码示例来源: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, SoundParameter parameter) {
  sound = Gdx.audio.newSound(file);
}

代码示例来源:origin: com.badlogicgames.gdx/gdx

@Override
public void loadAsync (AssetManager manager, String fileName, FileHandle file, MusicParameter parameter) {
  music = Gdx.audio.newMusic(file);
}

代码示例来源:origin: net.mostlyoriginal.artemis-odb/contrib-components-libgdx

protected void loadSounds(String[] soundnames) {
  for (String identifier : soundnames) {
    sounds.put(identifier, Gdx.audio.newSound(Gdx.files.internal("sfx/" + identifier + ".mp3")));
  }
}

代码示例来源: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: net.mostlyoriginal.artemis-odb/contrib-jam

protected void loadSounds(String[] soundnames) {
  for (String identifier : soundnames) {
    sounds.put(identifier, Gdx.audio.newSound(Gdx.files.internal("sfx/" + identifier + ".mp3")));
  }
}

代码示例来源:origin: Mknsri/Drunk-Toss

public static Music loadMusic(String path) {
  return Gdx.audio.newMusic(Gdx.files.internal(path));
}

相关文章