From a7c20b7700ca6300732465be7d58829c25149a12 Mon Sep 17 00:00:00 2001 From: xufulong <839789740@qq.com> Date: Thu, 26 Dec 2019 00:46:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9OnLive=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改OnLive模块直播地址 --- OnLive/src/main/AndroidManifest.xml | 20 +-- .../living/activity/MultiScreenActivity.java | 114 ++++++++++-------- .../living/activity/RtspLiveActivity.java | 32 +++-- 3 files changed, 91 insertions(+), 75 deletions(-) diff --git a/OnLive/src/main/AndroidManifest.xml b/OnLive/src/main/AndroidManifest.xml index 9bed52c..59c8ed0 100644 --- a/OnLive/src/main/AndroidManifest.xml +++ b/OnLive/src/main/AndroidManifest.xml @@ -18,11 +18,11 @@ android:label="@string/app_name" android:screenOrientation="landscape" android:theme="@style/FullscreenTheme"> - - - - - + + + + + - - - - - + + + + + diff --git a/OnLive/src/main/java/com/frank/living/activity/MultiScreenActivity.java b/OnLive/src/main/java/com/frank/living/activity/MultiScreenActivity.java index 6b9d332..21d5af5 100644 --- a/OnLive/src/main/java/com/frank/living/activity/MultiScreenActivity.java +++ b/OnLive/src/main/java/com/frank/living/activity/MultiScreenActivity.java @@ -6,18 +6,23 @@ import android.content.Intent; import android.content.IntentFilter; import android.os.PowerManager; import android.os.Process; + import androidx.appcompat.app.AppCompatActivity; + import android.os.Bundle; import android.text.TextUtils; import android.util.Log; import android.view.View; + import com.frank.living.R; import com.frank.living.constant.Constants; import com.frank.living.listener.OnDoubleClickListener; import com.frank.living.listener.IjkPlayerListener; import com.frank.living.widget.IjkVideoView; + import java.util.HashMap; import java.util.TreeMap; + import tv.danmaku.ijk.media.player.IMediaPlayer; 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 */ -public class MultiScreenActivity extends AppCompatActivity{ +public class MultiScreenActivity extends AppCompatActivity { private static final String TAG = MultiScreenActivity.class.getSimpleName(); @@ -65,17 +70,17 @@ public class MultiScreenActivity extends AppCompatActivity{ } - private void initView(){ - mVideoView1 = (IjkVideoView) findViewById(R.id.video_view1); - mVideoView2 = (IjkVideoView) findViewById(R.id.video_view2); - mVideoView3 = (IjkVideoView) findViewById(R.id.video_view3); - mVideoView4 = (IjkVideoView) findViewById(R.id.video_view4); + private void initView() { + mVideoView1 = findViewById(R.id.video_view1); + mVideoView2 = findViewById(R.id.video_view2); + mVideoView3 = findViewById(R.id.video_view3); + mVideoView4 = findViewById(R.id.video_view4); divider1 = findViewById(R.id.divider1); divider2 = findViewById(R.id.divider2); } - private void initListener(){ + private void initListener() { mVideoView1.setOnTouchListener(new OnDoubleClickListener(new OnDoubleClickListener.OnDoubleClick() { @Override public void onDouble() { @@ -102,7 +107,7 @@ public class MultiScreenActivity extends AppCompatActivity{ })); } - private void setupView(){ + private void setupView() { //第一路投屏默认全屏 enterFullScreen(1); mVideoView1.setVideoPath(url); @@ -126,8 +131,8 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 外部传进来的数据:URL */ - private void parseIntent(){ - for (int i=1; i<=4; i++){ + private void parseIntent() { + for (int i = 1; i <= 4; i++) { channelMap.put(i, false); } clientMap.put(ipAddress, 1); @@ -135,31 +140,30 @@ public class MultiScreenActivity extends AppCompatActivity{ Intent intent = getIntent(); String url = intent.getStringExtra("url"); - if(!TextUtils.isEmpty(url)){ + if (!TextUtils.isEmpty(url)) { this.url = url; } String ip = intent.getStringExtra("ip"); - if (!TextUtils.isEmpty(ip)){ + if (!TextUtils.isEmpty(ip)) { ipAddress = ip; } } //唤醒屏幕 - private void wakeUp(){ + private void wakeUp() { PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); if (powerManager == null) return; PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK - |PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); + | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG); wakeLock.acquire(1000); wakeLock.release(); } /** * 配置播放器参数项 - * */ - private void setOptions(IjkMediaPlayer ijkPlayer){ + private void setOptions(IjkMediaPlayer ijkPlayer) { if (ijkPlayer == null) return; 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(); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.ACTION_CLIENT_REMOVE); @@ -196,8 +200,8 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 注销广播 */ - private void unregisterBroadcast(){ - if(customReceiver != null){ + private void unregisterBroadcast() { + if (customReceiver != null) { unregisterReceiver(customReceiver); customReceiver = null; } @@ -210,22 +214,22 @@ public class MultiScreenActivity extends AppCompatActivity{ @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if(action == null) + if (action == null) return; Log.e(TAG, "onReceive=" + action); - switch (action){ + switch (action) { case Constants.ACTION_CLIENT_REMOVE: //移除投屏 int num = intent.getIntExtra("clientNum", 0); - if (num == 0){ + if (num == 0) { Process.killProcess(Process.myPid()); - }else if (num > 0){ + } else if (num > 0) { String ipAddress = intent.getStringExtra("ipAddress"); int target = clientMap.get(ipAddress); removeClient(target); clientMap.remove(ipAddress); channelMap.put(target, false); //多屏变为单屏时,自动切换为全屏 - if (num == 1){ + if (num == 1) { int castingChannel = getCastingChannel(); enterFullScreen(castingChannel); } @@ -241,7 +245,7 @@ public class MultiScreenActivity extends AppCompatActivity{ channelMap.put(channel, true); addClient(channel, otherUrl); //单屏变为两路投屏时,自动切换为多屏模式 - if (clientNum == 2){ + if (clientNum == 2) { exitFullScreen(); } break; @@ -253,12 +257,13 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 选择空闲通道 + * * @param clientNum clientNum * @return idleChannel */ - private int selectIdleChannel(int clientNum){ - for (int channel = 1; channel < clientNum; channel++){ - if (!channelMap.get(channel)){ + private int selectIdleChannel(int clientNum) { + for (int channel = 1; channel < clientNum; channel++) { + if (!channelMap.get(channel)) { return channel; } } @@ -267,11 +272,12 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 获取当前投屏通道 + * * @return idleChannel */ - private int getCastingChannel(){ - for (int channel = 1; channel <= 4; channel++){ - if (channelMap.get(channel)){ + private int getCastingChannel() { + for (int channel = 1; channel <= 4; channel++) { + if (channelMap.get(channel)) { return channel; } } @@ -280,11 +286,12 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 添加客户端 - * @param target target + * + * @param target target * @param clientUrl clientUrl */ - private void addClient(int target, String clientUrl){ - switch (target){ + private void addClient(int target, String clientUrl) { + switch (target) { case 1: mVideoView1.setVisibility(View.VISIBLE); mVideoView1.setVideoPath(clientUrl); @@ -312,10 +319,11 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 移除客户端 + * * @param target target */ - private void removeClient(int target){ - switch (target){ + private void removeClient(int target) { + switch (target) { case 1: mVideoView1.stopPlayback(); mVideoView1.setVisibility(View.GONE); @@ -340,7 +348,7 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 隐藏分割线 */ - private void hideDivider(){ + private void hideDivider() { divider1.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); divider2.setVisibility(View.VISIBLE); } /** * 进入全屏模式 + * * @param channel channel */ - private void enterFullScreen(int channel){ + private void enterFullScreen(int channel) { hideDivider(); - switch (channel){ + switch (channel) { case 1: mVideoView1.setRenderViewVisible(); mVideoView2.setRenderViewGone(); @@ -412,7 +421,7 @@ public class MultiScreenActivity extends AppCompatActivity{ /** * 退出全屏模式 */ - private void exitFullScreen(){ + private void exitFullScreen() { mVideoView1.setRenderViewVisible(); mVideoView2.setRenderViewVisible(); mVideoView3.setRenderViewVisible(); @@ -425,18 +434,19 @@ public class MultiScreenActivity extends AppCompatActivity{ mVideoView4.setVisibility(View.VISIBLE); } -/** - * 切换分屏模式 - * @param channel channel - */ -private void changeScreenMode(int channel){ - isMultiScreen = !isMultiScreen; - if (isMultiScreen){ - enterFullScreen(channel); - }else { - exitFullScreen(); + /** + * 切换分屏模式 + * + * @param channel channel + */ + private void changeScreenMode(int channel) { + isMultiScreen = !isMultiScreen; + if (isMultiScreen) { + enterFullScreen(channel); + } else { + exitFullScreen(); + } } -} @Override protected void onDestroy() { diff --git a/OnLive/src/main/java/com/frank/living/activity/RtspLiveActivity.java b/OnLive/src/main/java/com/frank/living/activity/RtspLiveActivity.java index e9a6981..3d83d14 100644 --- a/OnLive/src/main/java/com/frank/living/activity/RtspLiveActivity.java +++ b/OnLive/src/main/java/com/frank/living/activity/RtspLiveActivity.java @@ -1,17 +1,22 @@ package com.frank.living.activity; import android.os.Bundle; + import androidx.appcompat.app.AppCompatActivity; + import android.util.Log; import android.view.View; import android.widget.ImageButton; import android.widget.TableLayout; + import com.frank.living.R; import com.frank.living.listener.IjkPlayerListener; + import tv.danmaku.ijk.media.player.IjkMediaPlayer; + 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(); @@ -22,7 +27,8 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList private boolean isPause; 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 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.native_profileBegin("libijkplayer.so"); - TableLayout mHudView = (TableLayout) findViewById(R.id.hud_view); - mVideoView = (IjkVideoView) findViewById(R.id.video_view); + TableLayout mHudView = findViewById(R.id.hud_view); + mVideoView = findViewById(R.id.video_view); mVideoView.setHudView(mHudView); mVideoView.setIjkPlayerListener(this); mVideoView.setVideoPath(url); mVideoView.start(); - btnPlay = (ImageButton) findViewById(R.id.btn_play); + btnPlay = findViewById(R.id.btn_play); btnPlay.setOnClickListener(this); - btnSound = (ImageButton) findViewById(R.id.btn_sound); + btnSound = findViewById(R.id.btn_sound); btnSound.setOnClickListener(this); } - private void initOptions(){ + private void initOptions() { if (ijkMediaPlayer == null) return; Log.e(TAG, "initOptions"); @@ -82,13 +88,13 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList @Override public void onClick(View v) { - switch (v.getId()){ + switch (v.getId()) { case R.id.btn_play: isPause = !isPause; - if (isPause){//直播暂停 + if (isPause) {//直播暂停 mVideoView.pause(); btnPlay.setBackgroundResource(R.drawable.ic_play); - }else {//直播继续 + } else {//直播继续 mVideoView.start(); btnPlay.setBackgroundResource(R.drawable.ic_pause); } @@ -97,10 +103,10 @@ public class RtspLiveActivity extends AppCompatActivity implements IjkPlayerList isSilence = !isSilence; if (ijkMediaPlayer == null) return; - if (isSilence){ + if (isSilence) { ijkMediaPlayer.setVolume(0, 0); btnSound.setBackgroundResource(R.drawable.ic_sound); - }else { + } else { ijkMediaPlayer.setVolume(50, 50); btnSound.setBackgroundResource(R.drawable.ic_silence); }