开发者

Sounds cut off early on some phones

开发者 https://www.devze.com 2023-01-15 04:51 出处:网络
I\'m the developer of a Soundboard app. A lot of users have reported me that in their phones some of the sounds cut off early. I have a Nexus One and a HTC Tattoo and everything works fine, I\'ve neve

I'm the developer of a Soundboard app. A lot of users have reported me that in their phones some of the sounds cut off early. I have a Nexus One and a HTC Tattoo and everything works fine, I've never noticed the cut off in my phones.

This is my code for the audio part:

First, I have a MediaPlayer object in my main class:

private MediaPlayer mp = null;

And when I puss a button, this is the code:

    private OnClickListener onClickSound = new OnClickListener() {

    public void onClick(View v) {
        if(mp != null){
            mp.stop();
            mp.release();
            mp = null;
        }

        mp = MediaPlayer.create(getBaseContext(), mp3id));
        mp.start();
        mp.setOnCompletionListener(completionListener);
    }
};

And this is the completionListener:

    MediaPlayer.OnCompletionListener completionListener = new MediaPlayer.OnCompletionListener(){

    public void onCompletion(MediaPlayer mediaP) {
        if(mp != null && !mp.isPlaying()){
            mp.stop();
            mp.release();
            mp开发者_开发技巧 = null;
        }
    }

};

You guys have any clue?

Greetings


You're starting playing before player loads all the media. Use setOnPreparedListener to start only after player is ready.

0

精彩评论

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