一、项目结构:主要app和player
app结构
二、增加遥控器按键选台
修改LivePlayActivity.java
1、声明变量
public String channelId = "";
public Timer timer = new Timer();
public Toast mToast;
2、定义方法
private void mToastShow(String s){
mToast = Toast.makeText(LivePlayActivity.this, "", Toast.LENGTH_SHORT );
mToast.setText(s);
LinearLayout layout = (LinearLayout) mToast.getView();
TextView tv = (TextView) layout.getChildAt(0);
tv.setTextSize(86);
mToast.setGravity(Gravity.CENTER, 0, 0);
mToast.show();
}
private Handler handler = new Handler(){
@Override
public void handleMessage(Message msg){
switch (msg.what) {
case 1:
mToastShow(String.valueOf(msg.obj));
break;
case 2:
playChannel(0,Integer.parseInt(String.valueOf(msg.obj))-1,false);
break;
}
super.handleMessage(msg);
}
};
3、修改方法public boolean dispatchKeyEvent(KeyEvent event)
switch (keyCode) {}中增加如下代码:
default:
if(keyCode>=KeyEvent.KEYCODE_0 && keyCode<=KeyEvent.KEYCODE_9)
{
if(mToast != null)
{
mToast.cancel();
}
if(channelId=="") {
channelId +=keyCode-7;
mToastShow(channelId);
timer.schedule(new TimerTask() {
@Override
public void run() {
Message message = new Message();
message.what = 2;
message.obj = channelId;
handler.sendMessage(message);
channelId ="";
}
}, 2000);
}else {
channelId +=keyCode-7;
mToastShow(channelId);
}
}
break;
判断按键是0-9,
mToast.cancel();不显示
mToastShow(channelId);显示channelId
channelId为按键选择的频道号
timer计时器:2秒内的按键为选台数字,
4、比如遥控器连续按1和2,channelId为“12”,mToastShow显示数字12,timer.schedule以handler方式发送消息,handler.sendMessage(message)发送后,handleMessage方法调用playChannel()播放指定频道。
三、playChannel()方法参数
playChannel(0,Integer.parseInt(String.valueOf(msg.obj))-1,false);
第1个参数:频道分组序号,从0开始
第2个参数:频道在分组中的序号,从0开始
第3个参数:改变播放源,默认false
三、播放源json格式
lives为直播源,group为分组,channels为频道列表。全部为json数组型
{
"lives": [{"group": "分组1","channels": [
{"name":"CCTV1","urls":["url1","url2"]},
{"name":"CCTV2","urls":["url3","url4"]},
...
]},{"group": "分组2","channels": [...]}],
spider蜘蛛
sites站点
"sites":[
{ "key": "aa", "name": "bb", "type": 3, "api": "https://jihulab.com/yydfys/yydf/-/raw/main/yydf/lib/drpy2.min.js", "ext": "https://jihulab.com/yydfys/yydf/-/raw/main/yydf/lib/douban.js" },...
]
ijk解码 ,建议app设置中,选用硬解码
"ijk": [
{"group":"软解码","options":[{"category":4,"name":"opensles","value":"0"},{"category":4,"name":"overlay-format","value":"842225234"},{"category":4,"name":"framedrop","value":"1"},{"category":4,"name":"soundtouch","value":"1"},{"category":4,"name":"start-on-prepared","value":"1"},{"category":1,"name":"http-detect-rangeupport","value":"0"},{"category":1,"name":"fflags","value":"fastseek"},{"category":2,"name":"skip_loop_filter","value":"48"},{"category":4,"name":"reconnect","value":"1"},{"category":4,"name":"enable-accurateeek","value":"0"},{"category":4,"name":"mediacodec","value":"0"},{"category":4,"name":"mediacodec-auto-rotate","value":"0"},{"category":4,"name":"mediacodec-handle-resolution-change","value":"0"},{"category":4,"name":"mediacodec-hevc","value":"0"},{"category":1,"name":"dns_cache_timeout","value":"600000000"}]},
{"group":"硬解码","options":[{"category":4,"name":"opensles","value":"0"},{"category":4,"name":"overlay-format","value":"842225234"},{"category":4,"name":"framedrop","value":"1"},{"category":4,"name":"soundtouch","value":"1"},{"category":4,"name":"start-on-prepared","value":"1"},{"category":1,"name":"http-detect-rangeupport","value":"0"},{"category":1,"name":"fflags","value":"fastseek"},{"category":2,"name":"skip_loop_filter","value":"48"},{"category":4,"name":"reconnect","value":"1"},{"category":4,"name":"enable-accurateeek","value":"0"},{"category":4,"name":"mediacodec","value":"1"},{"category":4,"name":"mediacodec-auto-rotate","value":"1"},{"category":4,"name":"mediacodec-handle-resolution-change","value":"1"},{"category":4,"name":"mediacodec-hevc","value":"1"},{"category":1,"name":"dns_cache_timeout","value":"600000000"}]}],