作者Ferich (純粹的透明)
看板AndroidDev
標題[問題] Notification button 控制 app 播放
時間Fri Oct 25 14:24:10 2013
一開始去接值 第一次進入為null 按下notification後 會回傳值來控制
Intent _Intent = getIntent();
String text = _Intent.getStringExtra("mode");
if(text=null)
{
pre();
next();
seek();
play();
}else if(text.equals("next"))
{
Toast.makeText(this, "next", Toast.LENGTH_LONG).show();
}
-----------------
當音樂播放時 show出 notification
CharSequence title = "Play_control";
int icon = R.drawable.player_icon;
long when = System.currentTimeMillis();
Notification noti = new Notification(icon, title, when + 10000);
noti.flags = Notification.FLAG_INSISTENT;
RemoteViews remoteView = new RemoteViews(this.getPackageName(),
R.layout.music_player_notification);
remoteView.setImageViewResource(R.id.cover, R.drawable.cover);
remoteView.setTextViewText(R.id.text, filename(music_list[position]));
Intent _Intent_next = new Intent(this, Player_music.class);
_Intent_next.putExtra("mode", "next");
remoteView.setOnClickPendingIntent(R.id.ibtn_player_control_next,
_PendingIntent_next);
noti.contentIntent = _PendingIntent_next;
----------
這樣寫 他的值的確可以回來 並且回到app show出toast
但是參考了sony的播放器與kkbox後
他們可以直接以notification操作 下一首 上一首 暫停 播放 不需要回到app.
但是小弟的寫法會回去 並且開一個新的activity...
請問要如何控制原本的activity內的播放器 不需另開 也不需要把畫面跳回app?
請有經驗的捧油 參考一下 小弟疏漏的地方.
感謝看完~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.141.150.92
→ ted66:廣播試試 10/25 14:37
→ Ferich:感謝您 搞定了 broadcast 正解 10/25 22:22