|
|
@ -6,18 +6,23 @@ import android.content.Intent; |
|
|
|
import android.content.IntentFilter; |
|
|
|
import android.content.IntentFilter; |
|
|
|
import android.os.PowerManager; |
|
|
|
import android.os.PowerManager; |
|
|
|
import android.os.Process; |
|
|
|
import android.os.Process; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
|
|
|
|
import com.frank.living.R; |
|
|
|
import com.frank.living.R; |
|
|
|
import com.frank.living.constant.Constants; |
|
|
|
import com.frank.living.constant.Constants; |
|
|
|
import com.frank.living.listener.OnDoubleClickListener; |
|
|
|
import com.frank.living.listener.OnDoubleClickListener; |
|
|
|
import com.frank.living.listener.IjkPlayerListener; |
|
|
|
import com.frank.living.listener.IjkPlayerListener; |
|
|
|
import com.frank.living.widget.IjkVideoView; |
|
|
|
import com.frank.living.widget.IjkVideoView; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.TreeMap; |
|
|
|
import java.util.TreeMap; |
|
|
|
|
|
|
|
|
|
|
|
import tv.danmaku.ijk.media.player.IMediaPlayer; |
|
|
|
import tv.danmaku.ijk.media.player.IMediaPlayer; |
|
|
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer; |
|
|
|
import tv.danmaku.ijk.media.player.IjkMediaPlayer; |
|
|
|
|
|
|
|
|
|
|
@ -25,7 +30,7 @@ import tv.danmaku.ijk.media.player.IjkMediaPlayer; |
|
|
|
* 多路投屏直播 |
|
|
|
* 多路投屏直播 |
|
|
|
* Created by xufulong on 2019/01/04 |
|
|
|
* Created by xufulong on 2019/01/04 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
public class MultiScreenActivity extends AppCompatActivity { |
|
|
|
|
|
|
|
|
|
|
|
private static final String TAG = MultiScreenActivity.class.getSimpleName(); |
|
|
|
private static final String TAG = MultiScreenActivity.class.getSimpleName(); |
|
|
|
|
|
|
|
|
|
|
@ -65,17 +70,17 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initView(){ |
|
|
|
private void initView() { |
|
|
|
mVideoView1 = (IjkVideoView) findViewById(R.id.video_view1); |
|
|
|
mVideoView1 = findViewById(R.id.video_view1); |
|
|
|
mVideoView2 = (IjkVideoView) findViewById(R.id.video_view2); |
|
|
|
mVideoView2 = findViewById(R.id.video_view2); |
|
|
|
mVideoView3 = (IjkVideoView) findViewById(R.id.video_view3); |
|
|
|
mVideoView3 = findViewById(R.id.video_view3); |
|
|
|
mVideoView4 = (IjkVideoView) findViewById(R.id.video_view4); |
|
|
|
mVideoView4 = findViewById(R.id.video_view4); |
|
|
|
|
|
|
|
|
|
|
|
divider1 = findViewById(R.id.divider1); |
|
|
|
divider1 = findViewById(R.id.divider1); |
|
|
|
divider2 = findViewById(R.id.divider2); |
|
|
|
divider2 = findViewById(R.id.divider2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void initListener(){ |
|
|
|
private void initListener() { |
|
|
|
mVideoView1.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.OnDoubleClick() { |
|
|
|
mVideoView1.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.OnDoubleClick() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onDouble() { |
|
|
|
public void onDouble() { |
|
|
@ -102,7 +107,7 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
})); |
|
|
|
})); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setupView(){ |
|
|
|
private void setupView() { |
|
|
|
//第一路投屏默认全屏
|
|
|
|
//第一路投屏默认全屏
|
|
|
|
enterFullScreen(1); |
|
|
|
enterFullScreen(1); |
|
|
|
mVideoView1.setVideoPath(url); |
|
|
|
mVideoView1.setVideoPath(url); |
|
|
@ -126,8 +131,8 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 外部传进来的数据:URL |
|
|
|
* 外部传进来的数据:URL |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void parseIntent(){ |
|
|
|
private void parseIntent() { |
|
|
|
for (int i=1; i<=4; i++){ |
|
|
|
for (int i = 1; i <= 4; i++) { |
|
|
|
channelMap.put(i, false); |
|
|
|
channelMap.put(i, false); |
|
|
|
} |
|
|
|
} |
|
|
|
clientMap.put(ipAddress, 1); |
|
|
|
clientMap.put(ipAddress, 1); |
|
|
@ -135,31 +140,30 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
Intent intent = getIntent(); |
|
|
|
Intent intent = getIntent(); |
|
|
|
String url = intent.getStringExtra("url"); |
|
|
|
String url = intent.getStringExtra("url"); |
|
|
|
if(!TextUtils.isEmpty(url)){ |
|
|
|
if (!TextUtils.isEmpty(url)) { |
|
|
|
this.url = url; |
|
|
|
this.url = url; |
|
|
|
} |
|
|
|
} |
|
|
|
String ip = intent.getStringExtra("ip"); |
|
|
|
String ip = intent.getStringExtra("ip"); |
|
|
|
if (!TextUtils.isEmpty(ip)){ |
|
|
|
if (!TextUtils.isEmpty(ip)) { |
|
|
|
ipAddress = ip; |
|
|
|
ipAddress = ip; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//唤醒屏幕
|
|
|
|
//唤醒屏幕
|
|
|
|
private void wakeUp(){ |
|
|
|
private void wakeUp() { |
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
|
|
|
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); |
|
|
|
if (powerManager == null) |
|
|
|
if (powerManager == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
|
|
|
PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
|
|
|
|PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); |
|
|
|
| PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); |
|
|
|
wakeLock.acquire(1000); |
|
|
|
wakeLock.acquire(1000); |
|
|
|
wakeLock.release(); |
|
|
|
wakeLock.release(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 配置播放器参数项 |
|
|
|
* 配置播放器参数项 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void setOptions(IjkMediaPlayer ijkPlayer){ |
|
|
|
private void setOptions(IjkMediaPlayer ijkPlayer) { |
|
|
|
if (ijkPlayer == null) |
|
|
|
if (ijkPlayer == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "fast", 1);//不额外优化
|
|
|
|
ijkPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_PLAYER, "fast", 1);//不额外优化
|
|
|
@ -185,7 +189,7 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 注册广播 |
|
|
|
* 注册广播 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void registerBroadcast(){ |
|
|
|
private void registerBroadcast() { |
|
|
|
customReceiver = new CustomReceiver(); |
|
|
|
customReceiver = new CustomReceiver(); |
|
|
|
IntentFilter intentFilter = new IntentFilter(); |
|
|
|
IntentFilter intentFilter = new IntentFilter(); |
|
|
|
intentFilter.addAction(Constants.ACTION_CLIENT_REMOVE); |
|
|
|
intentFilter.addAction(Constants.ACTION_CLIENT_REMOVE); |
|
|
@ -196,8 +200,8 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 注销广播 |
|
|
|
* 注销广播 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void unregisterBroadcast(){ |
|
|
|
private void unregisterBroadcast() { |
|
|
|
if(customReceiver != null){ |
|
|
|
if (customReceiver != null) { |
|
|
|
unregisterReceiver(customReceiver); |
|
|
|
unregisterReceiver(customReceiver); |
|
|
|
customReceiver = null; |
|
|
|
customReceiver = null; |
|
|
|
} |
|
|
|
} |
|
|
@ -210,22 +214,22 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onReceive(Context context, Intent intent) { |
|
|
|
public void onReceive(Context context, Intent intent) { |
|
|
|
String action = intent.getAction(); |
|
|
|
String action = intent.getAction(); |
|
|
|
if(action == null) |
|
|
|
if (action == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
Log.e(TAG, "onReceive=" + action); |
|
|
|
Log.e(TAG, "onReceive=" + action); |
|
|
|
switch (action){ |
|
|
|
switch (action) { |
|
|
|
case Constants.ACTION_CLIENT_REMOVE: //移除投屏
|
|
|
|
case Constants.ACTION_CLIENT_REMOVE: //移除投屏
|
|
|
|
int num = intent.getIntExtra("clientNum", 0); |
|
|
|
int num = intent.getIntExtra("clientNum", 0); |
|
|
|
if (num == 0){ |
|
|
|
if (num == 0) { |
|
|
|
Process.killProcess(Process.myPid()); |
|
|
|
Process.killProcess(Process.myPid()); |
|
|
|
}else if (num > 0){ |
|
|
|
} else if (num > 0) { |
|
|
|
String ipAddress = intent.getStringExtra("ipAddress"); |
|
|
|
String ipAddress = intent.getStringExtra("ipAddress"); |
|
|
|
int target = clientMap.get(ipAddress); |
|
|
|
int target = clientMap.get(ipAddress); |
|
|
|
removeClient(target); |
|
|
|
removeClient(target); |
|
|
|
clientMap.remove(ipAddress); |
|
|
|
clientMap.remove(ipAddress); |
|
|
|
channelMap.put(target, false); |
|
|
|
channelMap.put(target, false); |
|
|
|
//多屏变为单屏时,自动切换为全屏
|
|
|
|
//多屏变为单屏时,自动切换为全屏
|
|
|
|
if (num == 1){ |
|
|
|
if (num == 1) { |
|
|
|
int castingChannel = getCastingChannel(); |
|
|
|
int castingChannel = getCastingChannel(); |
|
|
|
enterFullScreen(castingChannel); |
|
|
|
enterFullScreen(castingChannel); |
|
|
|
} |
|
|
|
} |
|
|
@ -241,7 +245,7 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
channelMap.put(channel, true); |
|
|
|
channelMap.put(channel, true); |
|
|
|
addClient(channel, otherUrl); |
|
|
|
addClient(channel, otherUrl); |
|
|
|
//单屏变为两路投屏时,自动切换为多屏模式
|
|
|
|
//单屏变为两路投屏时,自动切换为多屏模式
|
|
|
|
if (clientNum == 2){ |
|
|
|
if (clientNum == 2) { |
|
|
|
exitFullScreen(); |
|
|
|
exitFullScreen(); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -253,12 +257,13 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 选择空闲通道 |
|
|
|
* 选择空闲通道 |
|
|
|
|
|
|
|
* |
|
|
|
* @param clientNum clientNum |
|
|
|
* @param clientNum clientNum |
|
|
|
* @return idleChannel |
|
|
|
* @return idleChannel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private int selectIdleChannel(int clientNum){ |
|
|
|
private int selectIdleChannel(int clientNum) { |
|
|
|
for (int channel = 1; channel < clientNum; channel++){ |
|
|
|
for (int channel = 1; channel < clientNum; channel++) { |
|
|
|
if (!channelMap.get(channel)){ |
|
|
|
if (!channelMap.get(channel)) { |
|
|
|
return channel; |
|
|
|
return channel; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -267,11 +272,12 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 获取当前投屏通道 |
|
|
|
* 获取当前投屏通道 |
|
|
|
|
|
|
|
* |
|
|
|
* @return idleChannel |
|
|
|
* @return idleChannel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private int getCastingChannel(){ |
|
|
|
private int getCastingChannel() { |
|
|
|
for (int channel = 1; channel <= 4; channel++){ |
|
|
|
for (int channel = 1; channel <= 4; channel++) { |
|
|
|
if (channelMap.get(channel)){ |
|
|
|
if (channelMap.get(channel)) { |
|
|
|
return channel; |
|
|
|
return channel; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -280,11 +286,12 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 添加客户端 |
|
|
|
* 添加客户端 |
|
|
|
* @param target target |
|
|
|
* |
|
|
|
|
|
|
|
* @param target target |
|
|
|
* @param clientUrl clientUrl |
|
|
|
* @param clientUrl clientUrl |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void addClient(int target, String clientUrl){ |
|
|
|
private void addClient(int target, String clientUrl) { |
|
|
|
switch (target){ |
|
|
|
switch (target) { |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
mVideoView1.setVisibility(View.VISIBLE); |
|
|
|
mVideoView1.setVisibility(View.VISIBLE); |
|
|
|
mVideoView1.setVideoPath(clientUrl); |
|
|
|
mVideoView1.setVideoPath(clientUrl); |
|
|
@ -312,10 +319,11 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 移除客户端 |
|
|
|
* 移除客户端 |
|
|
|
|
|
|
|
* |
|
|
|
* @param target target |
|
|
|
* @param target target |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void removeClient(int target){ |
|
|
|
private void removeClient(int target) { |
|
|
|
switch (target){ |
|
|
|
switch (target) { |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
mVideoView1.stopPlayback(); |
|
|
|
mVideoView1.stopPlayback(); |
|
|
|
mVideoView1.setVisibility(View.GONE); |
|
|
|
mVideoView1.setVisibility(View.GONE); |
|
|
@ -340,7 +348,7 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 隐藏分割线 |
|
|
|
* 隐藏分割线 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void hideDivider(){ |
|
|
|
private void hideDivider() { |
|
|
|
divider1.setVisibility(View.GONE); |
|
|
|
divider1.setVisibility(View.GONE); |
|
|
|
divider2.setVisibility(View.GONE); |
|
|
|
divider2.setVisibility(View.GONE); |
|
|
|
} |
|
|
|
} |
|
|
@ -348,18 +356,19 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 显示分割线 |
|
|
|
* 显示分割线 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void showDivider(){ |
|
|
|
private void showDivider() { |
|
|
|
divider1.setVisibility(View.VISIBLE); |
|
|
|
divider1.setVisibility(View.VISIBLE); |
|
|
|
divider2.setVisibility(View.VISIBLE); |
|
|
|
divider2.setVisibility(View.VISIBLE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 进入全屏模式 |
|
|
|
* 进入全屏模式 |
|
|
|
|
|
|
|
* |
|
|
|
* @param channel channel |
|
|
|
* @param channel channel |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void enterFullScreen(int channel){ |
|
|
|
private void enterFullScreen(int channel) { |
|
|
|
hideDivider(); |
|
|
|
hideDivider(); |
|
|
|
switch (channel){ |
|
|
|
switch (channel) { |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
|
mVideoView1.setRenderViewVisible(); |
|
|
|
mVideoView1.setRenderViewVisible(); |
|
|
|
mVideoView2.setRenderViewGone(); |
|
|
|
mVideoView2.setRenderViewGone(); |
|
|
@ -412,7 +421,7 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 退出全屏模式 |
|
|
|
* 退出全屏模式 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void exitFullScreen(){ |
|
|
|
private void exitFullScreen() { |
|
|
|
mVideoView1.setRenderViewVisible(); |
|
|
|
mVideoView1.setRenderViewVisible(); |
|
|
|
mVideoView2.setRenderViewVisible(); |
|
|
|
mVideoView2.setRenderViewVisible(); |
|
|
|
mVideoView3.setRenderViewVisible(); |
|
|
|
mVideoView3.setRenderViewVisible(); |
|
|
@ -425,18 +434,19 @@ public class MultiScreenActivity extends AppCompatActivity{ |
|
|
|
mVideoView4.setVisibility(View.VISIBLE); |
|
|
|
mVideoView4.setVisibility(View.VISIBLE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 切换分屏模式 |
|
|
|
* 切换分屏模式 |
|
|
|
* @param channel channel |
|
|
|
* |
|
|
|
*/ |
|
|
|
* @param channel channel |
|
|
|
private void changeScreenMode(int channel){ |
|
|
|
*/ |
|
|
|
isMultiScreen = !isMultiScreen; |
|
|
|
private void changeScreenMode(int channel) { |
|
|
|
if (isMultiScreen){ |
|
|
|
isMultiScreen = !isMultiScreen; |
|
|
|
enterFullScreen(channel); |
|
|
|
if (isMultiScreen) { |
|
|
|
}else { |
|
|
|
enterFullScreen(channel); |
|
|
|
exitFullScreen(); |
|
|
|
} else { |
|
|
|
|
|
|
|
exitFullScreen(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void onDestroy() { |
|
|
|
protected void onDestroy() { |
|
|
|