简体   繁体   中英

Audio File not playing Android

I am having trouble playing audio files. I am currently learning how to develop with android and libgdx. So i created this code to play an mp3 when the application opens. But it does not play at all. I keep getting the log below.

Code:

package com.soundfx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class SoundFx extends ApplicationAdapter {

    Sound sound;

    @Override
    public void create () {
        sound = Gdx.audio.newSound(Gdx.files.internal("Smile.mp3"));
        sound.play();
    }

    @Override
    public void render () {
    }
}

Log: http://imgur.com/gallery/bFUmXqA

I also get Sample rate (96000) out of range

Try reducing the sample rate of your file (down to 44100 Hz for instance). You can convert your sound file using one of the various software tools available, or even online converters.

Also bear in mind that the Sound class is only meant for small audio files, such as short sound effects, as the file will be entirely loaded into memory (please refer to Sound ). If the MP3 you are playing is actually a whole song, use the Music class instead to stream the audio file ( Music ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM