Streaming music
badlogic edited this page Sep 14, 2013
·
1 revision
For any sound that's longer than a few seconds it is preferable to stream it from disk instead of fully loading it into RAM. Libgdx provides a Music interface that lets you do that.
To load a Music instance we can do the following:
Music music = Gdx.audio.newMusic(Gdx.files.internal("data/mymusic.mp3"));This loads an MP3 file called "mymusic.mp3" from the internal directory data.
Playing back the music instance works as follows:
music.play();Of course you can set various playback attributes of the Music instance:
music.setVolume(0.5f); // sets the volume to half the maximum volume
music.setLooping(true); // will repeat playback until music.stop() is called
music.stop(); // stops the playback
music.pause(); // pauses the playback
music.play(); // resumes the playback
boolean isPlaying = music.isPlaying(); // obvious :)
boolean isLooping = music.isLooping(); // obvious as well :)
float position = music.getPosition(); // returns the playback position in secondsMusic instances are heavy, you should usually not have more than one or two at most loaded.
A Music instance needs to be disposed if it is no longer needed, to free up resources.
music.dispose();Pages 218
- Home
- 2D Animation
- 2D Particle Editor
- 2D ParticleEffects
- 3D animations and skinning
- 3D Graphics
- 3D Particle Effects
- a note from the translation
- A Simple Game
- Accelerometer
- Actions
- Admob in libgdx
- Airpush in Libgdx
- APK Expansions support
- Artificial Intelligence
- Asset manager
- Audio
- Back and menu key catching
- Bitmap fonts
- Box2d
- Build Infrastructure Setup
- Building libgdx from source
- Building Natives
- Building the Bullet wrapper
- Bullet physics
- Bullet Wrapper Contact callbacks
- Bullet Wrapper Custom classes
- Bullet Wrapper Debugging
- Bullet Wrapper Setup
- Bullet Wrapper Using models
- Bullet Wrapper Using the wrapper
- Bullet Wrapper Contact callbacks
- Bullet Wrapper Custom classes
- Bullet Wrapper Debugging
- Bullet Wrapper Setup
- Bullet Wrapper Using models
- Bullet Wrapper Using the wrapper
- Bundling a JRE
- Circles, planes, rays, etc.
- Clearing the screen
- Clipping, with the use of scissorstack
- Collections
- Color Markup Language
- Community & Support
- Compass
- Configuration & querying
- Configuration & Querying
- Configuration & Querying
- Continuous & non continuous rendering
- Continuous & Non Continuous Rendering
- Contributing
- Controllers
- Coordinate systems
- Creating a Separate Assets Project in Eclipse
- Creating and texturing 3d models in blender for libgdx
- Cursor visibility & catching
- Cursor Visibility & Catching
- Decals
- Dependency management with Gradle
- Deploying as an Applet
- Deploying your application
- Distance field fonts
- Event handling
- Excelsior JET and libGDX
- Extending the simple game
- External tutorials
- File handling
- File module
- Frame buffer objects
- Games built with libgdx
- Gdx audio
- gdx dialogs
- gdx facebook
- Gdx freetype
- gdx kiwi
- gdx lml
- gdx pay
- Gesture detection
- Getting Help
- Getting ready for #libGDXJAM
- Goals & Features
- Google Mobile Ads in Libgdx (replaces deprecated AdMob)
- Google Play Games Services in LibGDX
- Google Summer of Code 2014
- Gradle and Eclipse
- Gradle and IntelliJ IDEA
- Gradle and NetBeans
- Gradle on the Commandline
- Graphics
- Graphics module
- GWT notes
- Gwt super dev mode
- Gyroscope
- Hello world
- Hiero
- HTML5 Backend and GWT Specifics
- ImGui
- Importing Blender models in LibGDX
- Improving workflow with Gradle
- Input handling
- Integrating libgdx and the device camera
- Intel RealSense Integration
- Interfacing with platform specific code
- Internationalization and Localization
- Interpolation
- Introduction
- Ios notes
- Issue Tracker
- jnigen
- libgdx utils
- libgdx utils box2d
- Local LibGDX package use with GWT
- Logging
- Managing your assets
- Manual project setup
- Material and environment
- Math utilities
- Maven integration
- Memory management
- Mesh, color & texture
- Meshes
- ModelBatch
- ModelBuilder, MeshBuilder and MeshPartBuilder
- ModelCache
- Models
- Modules overview
- More Info
- Mouse, touch & keyboard
- Mouse, Touch and Keyboard
- My First Triangle (Example)
- Networking
- Nextpeer in libgdx
- Ninepatches
- On screen keyboard
- Opengl es support
- Orthographic camera
- Overlap2D
- Overlap2D survival guide for #libGDXJAM
- Packing atlases at runtime
- Packing atlases offline
- Path Editor
- Path interface and Splines
- Physics
- Pixmaps
- Playing pcm audio
- Pollfish in libgdx
- Polling
- Preferences
- Profiling
- ProGuard DexGuard and libGDX
- Project Setup Gradle
- Project setup, running & debugging
- Projection, viewport, & camera
- Querying
- Querying & configuring graphics (monitors, display modes, vsync)
- Querying & configuring graphics (monitors, display modes, vsync)
- Quick start
- Reading and writing JSON
- Reading and writing XML
- Recording pcm audio
- Reflection
- Release Process
- Rendering shapes
- Robovm notes
- Running Demos
- Running demos & tests
- Running Tests
- Saved game serialization
- Scene2d
- Scene2d.ui
- Screen & viewport
- Setting Up Google In App Billing
- Setting up your Development Environment (Eclipse, Intellij IDEA, NetBeans)
- Shaders
- Simple Car Racing Game
- Simple text input
- Skin
- Skin Properties
- Sound effects
- Spritebatch, textureregions, and sprite
- Spritebatch, Textureregions, and Sprites
- Starter classes and configuration
- Streaming music
- Swarm in libgdx
- Table
- Table Of Contents
- Taking a Screenshot
- TextButton
- Texture Compression
- Texture packer
- Textures & textureregions
- Textures & TextureRegions
- Textures, textureregion and spritebatch
- The application framework
- The life cycle
- Third Party Extension Support
- Third Party Extensions
- Third party services
- Threading
- Tile maps
- Universal Tween Engine
- Updating LibGDX
- Using libgdx with android studio
- Using libgdx with Clojure
- Using libgdx with intellij idea
- Using libGDX with Kotlin
- Using libGDX with other JVM languages
- Using libgdx with Python
- Using libgdx with Scala
- Using textureatlases
- Using with Groovy
- Vectors, matrices, quaternions
- Vibrator
- Video tutorials
- Viewports
- VisRuntime
- VisUI
- Wiki Style Guide
Table of Contents
Developer's Guide
The Application Framework
A Simple Game
Input Handling
Graphics
- Graphics
- Querying & configuring graphics (monitors, display modes, vsync)
- Continuous & Non-Continuous Rendering
- Clearing the Screen
- Taking a Screenshot
- Profiling
- Viewports
-
OpenGL ES Support
- Configuration & Querying OpenGL ??
- Direct Access ??
- Utility Classes
-Rendering Shapes
-Textures & TextureRegions
-Meshes
-Shaders
-Frame Buffer Objects
2D Graphics
- SpriteBatch, TextureRegions, and Sprites
- 2D Animation
- Clipping, With the Use of ScissorStack
- Orthographic Camera
- Mapping Touch Coordinates ??
- NinePatches
- Bitmap Fonts
- Using TextureAtlases
- Pixmaps
- Packing Atlases Offline
- Packing Atlases at Runtime
- Texture Compression
- 2D ParticleEffects
- Tile Maps
- scene2d
- scene2d.ui
- ImGui
Internationalization and Localization
Math Utilities
- Math Utilities
- Interpolation
- Vectors, Matrices, Quaternions
- Circles, Planes, Rays, etc.
- Path Interface and Splines
- Bounding Volumes ??
- Intersection & Overlap Testing ??
Extensions
- Artificial Intelligence
- gdx-freetype
- gdx-pay: cross-platform In-App-Purchasing API
- Physics
Using libGDX With Other JVM Languages
Third Party Services
Articles
- Getting Help
- External Tutorials
- Bundling a JRE
- Deploying as an Applet
- HTML5 Backend and GWT Specifics
- Getting ready for #libGDXJAM
- Coordinate systems
- Updating Your libGDX Version
- Adding Extensions and 3rd Party Libraries
- Publishing Your Own Extensions Via the Setup Application
- Improving Your Gradle Workflow
- Creating Asset Project in Eclipse