修改OnLive模块直播地址

修改OnLive模块直播地址
pull/107/head
xufulong 5 years ago
parent d80cbd80e8
commit a7c20b7700
  1. 20
      OnLive/src/main/AndroidManifest.xml
  2. 114
      OnLive/src/main/java/com/frank/living/activity/MultiScreenActivity.java
  3. 32
      OnLive/src/main/java/com/frank/living/activity/RtspLiveActivity.java

@ -18,11 +18,11 @@
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/FullscreenTheme"> android:theme="@style/FullscreenTheme">
<!--<intent-filter>--> <intent-filter>
<!--<action android:name="android.intent.action.MAIN" />--> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
<!--<category android:name="android.intent.category.LAUNCHER" />--> <category android:name="android.intent.category.LAUNCHER" />
<!--</intent-filter>--> </intent-filter>
</activity> </activity>
<activity <activity
@ -31,11 +31,11 @@
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape" android:screenOrientation="landscape"
android:theme="@style/FullscreenTheme"> android:theme="@style/FullscreenTheme">
<intent-filter> <!--<intent-filter>-->
<action android:name="android.intent.action.MAIN" /> <!--<action android:name="android.intent.action.MAIN" />-->
<action android:name="android.intent.action.VIEW" /> <!--<action android:name="android.intent.action.VIEW" />-->
<category android:name="android.intent.category.LAUNCHER" /> <!--<category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter> <!--</intent-filter>-->
</activity> </activity>
</application> </application>

@ -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() {

@ -1,17 +1,22 @@
package com.frank.living.activity; package com.frank.living.activity;
import android.os.Bundle; import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.TableLayout; import android.widget.TableLayout;
import com.frank.living.R; import com.frank.living.R;
import com.frank.living.listener.IjkPlayerListener; import com.frank.living.listener.IjkPlayerListener;
import tv.danmaku.ijk.media.player.IjkMediaPlayer; import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import com.frank.living.widget.IjkVideoView; import com.frank.living.widget.IjkVideoView;
public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerListener, View.OnClickListener{ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerListener, View.OnClickListener {
private final static String TAG = RtspLiveActivity.class.getSimpleName(); private final static String TAG = RtspLiveActivity.class.getSimpleName();
@ -22,7 +27,8 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList
private boolean isPause; private boolean isPause;
private boolean isSilence; private boolean isSilence;
private final static String url = "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov"; // private final static String url = "rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov";
private final static String url = "rtmp://58.200.131.2:1935/livetv/hunantv";
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -33,25 +39,25 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList
} }
private void init(){ private void init() {
IjkMediaPlayer.loadLibrariesOnce(null); IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so"); IjkMediaPlayer.native_profileBegin("libijkplayer.so");
TableLayout mHudView = (TableLayout) findViewById(R.id.hud_view); TableLayout mHudView = findViewById(R.id.hud_view);
mVideoView = (IjkVideoView) findViewById(R.id.video_view); mVideoView = findViewById(R.id.video_view);
mVideoView.setHudView(mHudView); mVideoView.setHudView(mHudView);
mVideoView.setIjkPlayerListener(this); mVideoView.setIjkPlayerListener(this);
mVideoView.setVideoPath(url); mVideoView.setVideoPath(url);
mVideoView.start(); mVideoView.start();
btnPlay = (ImageButton) findViewById(R.id.btn_play); btnPlay = findViewById(R.id.btn_play);
btnPlay.setOnClickListener(this); btnPlay.setOnClickListener(this);
btnSound = (ImageButton) findViewById(R.id.btn_sound); btnSound = findViewById(R.id.btn_sound);
btnSound.setOnClickListener(this); btnSound.setOnClickListener(this);
} }
private void initOptions(){ private void initOptions() {
if (ijkMediaPlayer == null) if (ijkMediaPlayer == null)
return; return;
Log.e(TAG, "initOptions"); Log.e(TAG, "initOptions");
@ -82,13 +88,13 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()){ switch (v.getId()) {
case R.id.btn_play: case R.id.btn_play:
isPause = !isPause; isPause = !isPause;
if (isPause){//直播暂停 if (isPause) {//直播暂停
mVideoView.pause(); mVideoView.pause();
btnPlay.setBackgroundResource(R.drawable.ic_play); btnPlay.setBackgroundResource(R.drawable.ic_play);
}else {//直播继续 } else {//直播继续
mVideoView.start(); mVideoView.start();
btnPlay.setBackgroundResource(R.drawable.ic_pause); btnPlay.setBackgroundResource(R.drawable.ic_pause);
} }
@ -97,10 +103,10 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList
isSilence = !isSilence; isSilence = !isSilence;
if (ijkMediaPlayer == null) if (ijkMediaPlayer == null)
return; return;
if (isSilence){ if (isSilence) {
ijkMediaPlayer.setVolume(0, 0); ijkMediaPlayer.setVolume(0, 0);
btnSound.setBackgroundResource(R.drawable.ic_sound); btnSound.setBackgroundResource(R.drawable.ic_sound);
}else { } else {
ijkMediaPlayer.setVolume(50, 50); ijkMediaPlayer.setVolume(50, 50);
btnSound.setBackgroundResource(R.drawable.ic_silence); btnSound.setBackgroundResource(R.drawable.ic_silence);
} }

Loading…
Cancel
Save