声音剪辑在android中过早停止

时间:2015-08-11 20:03:31

标签: android

我有一个Android应用程序,可以启动超过3分钟的音频剪辑。它经常完全播放,但大部分在完成前10-15秒失败。我正在调用一个为我运行的服务,如下所示:

public class MusicService extends Service implements OnCompletionListener {

    public int onStartCommand(Intent intent, int flags, int startId) {
        handleIntent( intent );
        if(StopppedClicked.equalsIgnoreCase("true")){
            stopSelf();
        }

        if (!mediaPlayer.isPlaying() && stopppedClicked.equalsIgnoreCase("False")) {
            if (settings.get_Vibrate_On_Notify().equalsIgnoreCase("Y")) {
                mediaPlayer.start();
            }
        }

        private void handleIntent( Intent intent ) {
            if( intent != null && intent.getAction() != null ) {
                if( intent.getAction().equalsIgnoreCase( ACTION_STOP ) ) {
                    mediaPlayer.stop();
                    //Stop media player here
                    NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                    notificationManager.cancel( 1002 );
                    StopppedClicked="True";
                    stopSelf();
                }
            }

        @Override
        public void onCreate() {
            DBHandler dbcall = DBHandler.getInstance(this);
            String PQType = dbcall.getPQType();
            if("S".equalsIgnoreCase(PQType )) {
                mediaPlayer = MediaPlayer.create(this, R.raw.s);// raw/s.mp3
            } else {
                mediaPlayer = MediaPlayer.create(this, R.raw.p);// raw/s.mp3
            }
            mediaPlayer.setOnCompletionListener(this);
        }

        public void onCompletion(MediaPlayer _mediaPlayer) {
            stopSelf();
        }
    }
}

0 个答案:

没有答案