현재 Notification으로 음악 컨트롤 할수있게 만들려고합니다.
한가지 문제가 있어서요.
메인화면에서 재생을 누르면 같이 notification으로 뜨게하였으나 시작하였을때 버튼이 재생버튼으로 그대로 있어서 로그찍어보니 isPlaying()이 처음부터 false로 뜨는데
false가 아닌 True로 만들거나
정 안되면 이미지를 바꿔주고 싶은데 가능할까요..
android.support.v4.app.NotificationCompat.Builder notificationBuilder = new android.support.v4.app.NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setStyle(new NotificationCompat.MediaStyle()
.addAction(new android.support.v4.app.NotificationCompat.Action(mp.isPlaying() ? R.drawable.ic_pause : R.drawable.ic_play,"",togglePlay))
Log.d("로그",""+mp.isPlaying());
public class CommandActions{
public final static String REWIND="REWIND";
public final static String TOGGLE_PLAY="TOGGLE_PLAY";
public final static String FORWARD="FORWARD";
public final static String CLOSE="CLOSE";
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent !=null){
String action=intent.getAction();
if (CommandActions.TOGGLE_PLAY.equals(action)){
if (isPlaying()){
pause();
}else {
playmusic();
}
}else if (CommandActions.REWIND.equals(action)){
rewind();
}else if (CommandActions.FORWARD.equals(action)){
forward();
}else if (CommandActions.CLOSE.equals(action)){
pause();
}
}
return super.onStartCommand(intent, flags, startId);
}