안녕하세요 ~
음악 스트리밍 기능을 추가하려고 하고 있습니다.
현재 구성은
MainActivity - web
PlaybackActivity - 플레이어 부분 (UI)
PlaybackService - 실제 음악 재생 부분
기반은 웹앱이고, javaScript로 playbackActivity를 실행해서, 서비스가 실행되는 구조입니다.
현재 문제가 Notification에 등록된 playbackActivity관련입니다.
Main (web) -> playbackactivity -> back -> back -> notification탭 -> playbackActivity 진입시에
서비스가 다시 시작되고 (음악도 재시작), 백버튼을 눌러보면 바로 홈으로 가게됩니다...
제가 원하는것은 어떤 사이클에서도 playActivity에선 플레이 상태를 표기하고 백했을때 원래 Main(web) 화면이 나왔으면 합니다.
// play Method in Service.java
Notification notification = new Notification(resId, text, System.currentTimeMillis());
notification.flags |= Notification.FLAG_ONGOING_EVENT;
Intent toLaunch = new Intent(PlaybackService.this, PlaybackActivity.class);
toLaunch.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intentBack = PendingIntent.getActivity(this, 0, toLaunch, 0);
notification.setLatestEventInfo(PlaybackService.this, getText(R.string.app_name), text, intentBack);
startForeground(PLAYBACKSERVICE_STATUS, notification);
pause시엔, stopForgeground(true); 처리해줬습니다.
// onStart Method in Activity.java
Activity realActivity = context.getParent();
if (realActivity == null) {
realActivity = context;
}
ContextWrapper cw = new ContextWrapper(realActivity);
cw.startService(new Intent(cw, PlaybackService.class));
// onStop Method in Activity.java
ContextWrapper cw;
cw.unbindService(sb);
mService = null;
대략의 코드는 이 정도입니다.
기본 뮤직 플레이어 소스를 받아서 참고하고 있지만, 생각보다 어렵네요..
조언 부탁드립니다 ~
해결했습니다. 확인해보니 서비스가 재생성되는것이 아니었고, 서비스 자체는 Rebind가 되었으나
Activity의 onCreate에서 서버로부터 파일 다운로드 -> 파싱 -> 완료 시 Service에게 재생 명령
의 구조이다보니.. Activity가 onCreate되면서 Service의 음악이 살짝 멈췄다가 다시 시작한것이었고
백버튼을 홈까지 눌렀을때 상위 액티비티가 안나오던것은 onBackPressed에 아래 코드를 삽입해 해결했습니다.
Intent intent = new Intent();
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.HOME");
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
| Intent.FLAG_ACTIVITY_FORWARD_RESULT
| Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent);
좀 어의없는 실수였습니다... - -




playbackactivity -> back -> back -> notification탭 ->
이건 뭘 의미하는 건가여? 설명좀 부탁.