开发者

MediaPlayer on Android only plays part of my song :(

I am trying to play a file using the MediaPlay. The first time it is played, it only plays for 1 or 2 seconds then cuts out and never returns. The secon开发者_C百科d time I play the song, it goes about 3 seconds. This function is in the onCreate function:

checkin.setOnCheckedChangeListener(new OnCheckedChangeListener(){
   public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
   MediaPlayer mp = MediaPlayer.create(context, R.raw.my_song);
   mp.start();
   v.vibrate(500);
   myLocation.getLocation(context, locationResult);
}

Is another thread clearing overriding the song? How do I get my whole song to play?


It looks like you're calling start() too quickly, before player actually loads all it needs to play the song. Use setOnPreparedListener() to start playing after the song is prepared for playback.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜