开发者

Problem looping audio on android app

Due to login confusion, i'm repeating this question. If any moderator sees this, i'd like to keep this one current, as I no longer can access my former login.

A bit of a problem ha开发者_StackOverflow社区s presented itself to me. I am trying to play a sound continously looping in my android app.

With MediaPlayer: MP3 plays alright, but there is a gap at the end which does not exist in the file. I read it had to do with the decoder, and that ogg should work. Tried using ogg, but still get the gap, which is definitely not on the file.

With SoundPool classes and ogg (using this fellow's interesting class: http://www.droidnova.com/creating-sound-effects-in-android-part-1,570.html),

the sound starts, and a fraction of a second later, it restarts. so I get a stutering half a second of the beginning of every file, without advancing further, because it is always going back to the beginning.

Is there something really wrong with media player and it's ability to loop audio? How about the freakishy stuttering soundpool?

Thank you very much for any assistance!

Note: Karthi_Heno suggested I do this:

MediaPlayer mediaPlayer;


setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();

try {
            AssetManager assetManager = getAssets();
            AssetFileDescriptor descriptor = assetManager.openFd("music.ogg");
            mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
                    descriptor.getStartOffset(), descriptor.getLength());
            mediaPlayer.prepare();
            mediaPlayer.setLooping(true);
        } catch (IOException e) {
            textView.setText("Couldn't load music file, " + e.getMessage());
            mediaPlayer = null;
        }

However, when i do this, getassets gives filenotfound, even though there IS a filein assets. any thoughts either on thisassets problem, or my audio loop question?

thanks. Yep, i'm an android newb alright, can't even get sound to loop alright.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜