提交 aaf1c7e1 编写于 作者: jinlong0603's avatar jinlong0603

去除format rtsp地址

上级 f30d4bcf
/* /*
Copyright (c) 2012-2017 EasyDarwin.ORG. All rights reserved. Copyright (c) 2012-2017 EasyDarwin.ORG. All rights reserved.
Github: https://github.com/EasyDarwin Github: https://github.com/EasyDarwin
WEChat: EasyDarwin WEChat: EasyDarwin
Website: http://www.easydarwin.org Website: http://www.easydarwin.org
*/ */
package org.easydarwin.easyipcamera.activity; package org.easydarwin.easyipcamera.activity;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.media.projection.MediaProjectionManager; import android.media.projection.MediaProjectionManager;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.view.Surface; import android.view.Surface;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import org.easydarwin.easyipcamera.R; import org.easydarwin.easyipcamera.R;
import org.easydarwin.easyipcamera.camera.EasyIPCamera; import org.easydarwin.easyipcamera.camera.EasyIPCamera;
import org.easydarwin.easyipcamera.camera.MediaStream; import org.easydarwin.easyipcamera.camera.MediaStream;
import org.easydarwin.easyipcamera.updatemgr.UpdateMgr; import org.easydarwin.easyipcamera.updatemgr.UpdateMgr;
import org.easydarwin.easyipcamera.util.Util; import org.easydarwin.easyipcamera.util.Util;
import org.easydarwin.easyipcamera.view.StatusInfoView; import org.easydarwin.easyipcamera.view.StatusInfoView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class StreamActivity extends AppCompatActivity implements SurfaceHolder.Callback, View.OnClickListener { public class StreamActivity extends AppCompatActivity implements SurfaceHolder.Callback, View.OnClickListener {
static final String TAG = "StreamActivity"; static final String TAG = "StreamActivity";
public static final int REQUEST_MEDIA_PROJECTION = 1002; public static final int REQUEST_MEDIA_PROJECTION = 1002;
//默认分辨率 //默认分辨率
int width = 640, height = 480; int width = 640, height = 480;
Button btnSwitch; Button btnSwitch;
Button btnSetting; Button btnSetting;
Button btnPushScreen; Button btnPushScreen;
TextView txtStreamAddress; TextView txtStreamAddress;
Button btnSwitchCemera; Button btnSwitchCemera;
Spinner spnResolution; Spinner spnResolution;
List<String> listResolution; List<String> listResolution;
MediaStream mMediaStream; MediaStream mMediaStream;
private StatusInfoView mDbgInfoPrint; private StatusInfoView mDbgInfoPrint;
static Intent mResultIntent; static Intent mResultIntent;
static int mResultCode; static int mResultCode;
boolean mBackgroundCamera; boolean mBackgroundCamera;
SurfaceHolder mSurfaceHolder; SurfaceHolder mSurfaceHolder;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate"); Log.d(TAG, "onCreate");
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
spnResolution = (Spinner) findViewById(R.id.spn_resolution); spnResolution = (Spinner) findViewById(R.id.spn_resolution);
mDbgInfoPrint = (StatusInfoView) findViewById(R.id.dbg_status_info); mDbgInfoPrint = (StatusInfoView) findViewById(R.id.dbg_status_info);
initDbgInfoView(); initDbgInfoView();
btnSwitch = (Button) findViewById(R.id.btn_switch); btnSwitch = (Button) findViewById(R.id.btn_switch);
btnSwitch.setOnClickListener(this); btnSwitch.setOnClickListener(this);
btnSetting = (Button) findViewById(R.id.btn_setting); btnSetting = (Button) findViewById(R.id.btn_setting);
btnSetting.setOnClickListener(this); btnSetting.setOnClickListener(this);
btnSwitchCemera = (Button) findViewById(R.id.btn_switchCamera); btnSwitchCemera = (Button) findViewById(R.id.btn_switchCamera);
btnSwitchCemera.setOnClickListener(this); btnSwitchCemera.setOnClickListener(this);
btnPushScreen = (Button) findViewById(R.id.push_screen); btnPushScreen = (Button) findViewById(R.id.push_screen);
btnPushScreen.setOnClickListener(this); btnPushScreen.setOnClickListener(this);
txtStreamAddress = (TextView) findViewById(R.id.txt_stream_address); txtStreamAddress = (TextView) findViewById(R.id.txt_stream_address);
SurfaceView surfaceView = (SurfaceView) findViewById(R.id.sv_surfaceview); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.sv_surfaceview);
surfaceView.getHolder().addCallback(this); surfaceView.getHolder().addCallback(this);
surfaceView.getHolder().setFixedSize(getResources().getDisplayMetrics().widthPixels, surfaceView.getHolder().setFixedSize(getResources().getDisplayMetrics().widthPixels,
getResources().getDisplayMetrics().heightPixels); getResources().getDisplayMetrics().heightPixels);
surfaceView.setOnClickListener(this); surfaceView.setOnClickListener(this);
listResolution = new ArrayList<String>(); listResolution = new ArrayList<String>();
listResolution = Util.getSupportResolution(this); listResolution = Util.getSupportResolution(this);
boolean supportdefault = listResolution.contains(String.format("%dx%d", width, height)); boolean supportdefault = listResolution.contains(String.format("%dx%d", width, height));
if (!supportdefault) { if (!supportdefault) {
String r = listResolution.get(0); String r = listResolution.get(0);
String[] splitR = r.split("x"); String[] splitR = r.split("x");
width = Integer.parseInt(splitR[0]); width = Integer.parseInt(splitR[0]);
height = Integer.parseInt(splitR[1]); height = Integer.parseInt(splitR[1]);
} }
if(EasyApplication.sMS == null){ if(EasyApplication.sMS == null){
mMediaStream = new MediaStream(getApplicationContext(), null); mMediaStream = new MediaStream(getApplicationContext(), null);
EasyApplication.sMS = mMediaStream; EasyApplication.sMS = mMediaStream;
} else { } else {
mMediaStream = EasyApplication.sMS; mMediaStream = EasyApplication.sMS;
if(mMediaStream.isOpen()){ if(mMediaStream.isOpen()){
btnSetting.setEnabled(false); btnSetting.setEnabled(false);
btnPushScreen.setEnabled(false); btnPushScreen.setEnabled(false);
btnSwitchCemera.setEnabled(false); btnSwitchCemera.setEnabled(false);
String ip = Util.getLocalIpAddress(); String ip = Util.getLocalIpAddress();
String port = EasyApplication.getEasyApplication().getPort(); String port = EasyApplication.getEasyApplication().getPort();
String id = EasyApplication.getEasyApplication().getId(); String id = EasyApplication.getEasyApplication().getId();
btnSwitch.setText("停止"); btnSwitch.setText("停止");
txtStreamAddress.setVisibility(View.VISIBLE); txtStreamAddress.setVisibility(View.VISIBLE);
StatusInfoView.getInstence().setVisibility(View.VISIBLE); StatusInfoView.getInstence().setVisibility(View.VISIBLE);
txtStreamAddress.setText(String.format(getRTSPAddr())); txtStreamAddress.setText(String.format(getRTSPAddr()));
} }
} }
mBackgroundCamera = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("background-camera", false); mBackgroundCamera = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("background-camera", false);
// if(mBackgroundCamera) { // if(mBackgroundCamera) {
// Intent bgcamera = new Intent(StreamActivity.this, BackgroundCameraService.class); // Intent bgcamera = new Intent(StreamActivity.this, BackgroundCameraService.class);
// stopService(bgcamera); // stopService(bgcamera);
// startService(bgcamera); // startService(bgcamera);
// } else { // } else {
// mMediaStream.setSurfaceHolder(mSurfaceHolder); // mMediaStream.setSurfaceHolder(mSurfaceHolder);
// mMediaStream.createCamera(); // mMediaStream.createCamera();
// mMediaStream.startPreview(); // mMediaStream.startPreview();
// } // }
mMediaStream.updateResolution(width, height); mMediaStream.updateResolution(width, height);
mMediaStream.setDgree(getDgree()); mMediaStream.setDgree(getDgree());
initSpninner(); initSpninner();
if (RecordService.mEasyIPCamera != null){ if (RecordService.mEasyIPCamera != null){
btnPushScreen.setText("停止推送屏幕"); btnPushScreen.setText("停止推送屏幕");
TextView viewById = (TextView) findViewById(R.id.txt_stream_address); TextView viewById = (TextView) findViewById(R.id.txt_stream_address);
viewById.setText(getRTSPAddr()); viewById.setText(getRTSPAddr());
} }
UpdateMgr update = new UpdateMgr(this); UpdateMgr update = new UpdateMgr(this);
update.checkUpdate(); update.checkUpdate();
} }
private void initDbgInfoView(){ private void initDbgInfoView(){
if(mDbgInfoPrint == null) if(mDbgInfoPrint == null)
return; return;
ViewGroup.LayoutParams lp = mDbgInfoPrint.getLayoutParams(); ViewGroup.LayoutParams lp = mDbgInfoPrint.getLayoutParams();
lp.height = getResources().getDisplayMetrics().heightPixels/4; lp.height = getResources().getDisplayMetrics().heightPixels/4;
mDbgInfoPrint.setLayoutParams(lp); mDbgInfoPrint.setLayoutParams(lp);
mDbgInfoPrint.requestLayout(); mDbgInfoPrint.requestLayout();
mDbgInfoPrint.setInstence(mDbgInfoPrint); mDbgInfoPrint.setInstence(mDbgInfoPrint);
} }
private void initSpninner() { private void initSpninner() {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spn_item, listResolution); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spn_item, listResolution);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnResolution.setAdapter(adapter); spnResolution.setAdapter(adapter);
int position = listResolution.indexOf(String.format("%dx%d", width, height)); int position = listResolution.indexOf(String.format("%dx%d", width, height));
spnResolution.setSelection(position,false); spnResolution.setSelection(position,false);
spnResolution.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { spnResolution.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String r = listResolution.get(position); String r = listResolution.get(position);
String[] splitR = r.split("x"); String[] splitR = r.split("x");
width = Integer.parseInt(splitR[0]); width = Integer.parseInt(splitR[0]);
height = Integer.parseInt(splitR[1]); height = Integer.parseInt(splitR[1]);
mMediaStream.updateResolution(width, height); mMediaStream.updateResolution(width, height);
mMediaStream.reStartStream(); mMediaStream.reStartStream();
} }
@Override @Override
public void onNothingSelected(AdapterView<?> parent) { public void onNothingSelected(AdapterView<?> parent) {
} }
}); });
} }
@Override @Override
public void surfaceCreated(final SurfaceHolder holder) { public void surfaceCreated(final SurfaceHolder holder) {
mBackgroundCamera = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("background-camera", false); mBackgroundCamera = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("background-camera", false);
mSurfaceHolder = holder; mSurfaceHolder = holder;
if(mBackgroundCamera){ if(mBackgroundCamera){
if(!mMediaStream.isOpen()) { if(!mMediaStream.isOpen()) {
Intent bgcamera = new Intent(StreamActivity.this, BackgroundCameraService.class); Intent bgcamera = new Intent(StreamActivity.this, BackgroundCameraService.class);
stopService(bgcamera); stopService(bgcamera);
startService(bgcamera); startService(bgcamera);
} }
} else { } else {
mMediaStream.setSurfaceHolder(holder); mMediaStream.setSurfaceHolder(holder);
mMediaStream.createCamera(); mMediaStream.createCamera();
mMediaStream.startPreview(); mMediaStream.startPreview();
} }
} }
@Override @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
} }
@Override @Override
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
if (!mBackgroundCamera) { if (!mBackgroundCamera) {
mMediaStream.stopPreview(); mMediaStream.stopPreview();
mMediaStream.destroyCamera(); mMediaStream.destroyCamera();
if (mMediaStream.isOpen()) { if (mMediaStream.isOpen()) {
mMediaStream.stopChannel(); mMediaStream.stopChannel();
} }
} }
} }
private int getDgree() { private int getDgree() {
int rotation = getWindowManager().getDefaultDisplay().getRotation(); int rotation = getWindowManager().getDefaultDisplay().getRotation();
int degrees = 0; int degrees = 0;
switch (rotation) { switch (rotation) {
case Surface.ROTATION_0: case Surface.ROTATION_0:
degrees = 0; degrees = 0;
break; // Natural orientation break; // Natural orientation
case Surface.ROTATION_90: case Surface.ROTATION_90:
degrees = 90; degrees = 90;
break; // Landscape left break; // Landscape left
case Surface.ROTATION_180: case Surface.ROTATION_180:
degrees = 180; degrees = 180;
break;// Upside down break;// Upside down
case Surface.ROTATION_270: case Surface.ROTATION_270:
degrees = 270; degrees = 270;
break;// Landscape right break;// Landscape right
} }
return degrees; return degrees;
} }
private String getRTSPAddr(){ private String getRTSPAddr(){
String ip = Util.getLocalIpAddress(); String ip = Util.getLocalIpAddress();
String port = EasyApplication.getEasyApplication().getPort(); String port = EasyApplication.getEasyApplication().getPort();
String id = EasyApplication.getEasyApplication().getId(); String id = EasyApplication.getEasyApplication().getId();
return String.format("rtsp://%s:%s/%s", ip, port, id); return String.format("rtsp://%s:%s/%s", ip, port, id);
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.btn_switch: case R.id.btn_switch:
StatusInfoView.getInstence().clearMsg(); StatusInfoView.getInstence().clearMsg();
if (!mMediaStream.isOpen()) { if (!mMediaStream.isOpen()) {
btnSetting.setEnabled(false); btnSetting.setEnabled(false);
btnPushScreen.setEnabled(false); btnPushScreen.setEnabled(false);
btnSwitchCemera.setEnabled(false); btnSwitchCemera.setEnabled(false);
String ip = Util.getLocalIpAddress(); String ip = Util.getLocalIpAddress();
String port = EasyApplication.getEasyApplication().getPort(); String port = EasyApplication.getEasyApplication().getPort();
String id = EasyApplication.getEasyApplication().getId(); String id = EasyApplication.getEasyApplication().getId();
mMediaStream.startChannel(ip, port, id); mMediaStream.startChannel(ip, port, id);
btnSwitch.setText("停止"); btnSwitch.setText("停止");
txtStreamAddress.setVisibility(View.VISIBLE); txtStreamAddress.setVisibility(View.VISIBLE);
StatusInfoView.getInstence().setVisibility(View.VISIBLE); StatusInfoView.getInstence().setVisibility(View.VISIBLE);
txtStreamAddress.setText(String.format(getRTSPAddr())); txtStreamAddress.setText(getRTSPAddr());
} else { } else {
txtStreamAddress.setVisibility(View.INVISIBLE); txtStreamAddress.setVisibility(View.INVISIBLE);
StatusInfoView.getInstence().setVisibility(View.INVISIBLE); StatusInfoView.getInstence().setVisibility(View.INVISIBLE);
mMediaStream.stopChannel(); mMediaStream.stopChannel();
btnSwitch.setText("推送摄像头"); btnSwitch.setText("推送摄像头");
btnSetting.setEnabled(true); btnSetting.setEnabled(true);
btnPushScreen.setEnabled(true); btnPushScreen.setEnabled(true);
btnSwitchCemera.setEnabled(true); btnSwitchCemera.setEnabled(true);
} }
break; break;
case R.id.btn_setting: case R.id.btn_setting:
startActivity(new Intent(this, SettingActivity.class)); startActivity(new Intent(this, SettingActivity.class));
break; break;
case R.id.sv_surfaceview: case R.id.sv_surfaceview:
try { try {
mMediaStream.getCamera().autoFocus(null); mMediaStream.getCamera().autoFocus(null);
} catch (Exception e) { } catch (Exception e) {
} }
break; break;
case R.id.btn_switchCamera: { case R.id.btn_switchCamera: {
mMediaStream.setDgree(getDgree()); mMediaStream.setDgree(getDgree());
mMediaStream.switchCamera(); mMediaStream.switchCamera();
break; break;
} }
case R.id.push_screen: case R.id.push_screen:
if (!mMediaStream.isOpen()) { if (!mMediaStream.isOpen()) {
spnResolution.setEnabled(true); spnResolution.setEnabled(true);
} }
//sendMessage(""); //sendMessage("");
boolean SWcodec = PreferenceManager.getDefaultSharedPreferences(EasyApplication.getEasyApplication()).getBoolean("key-sw-codec", false); boolean SWcodec = PreferenceManager.getDefaultSharedPreferences(EasyApplication.getEasyApplication()).getBoolean("key-sw-codec", false);
if(SWcodec){ if(SWcodec){
new AlertDialog.Builder(this).setMessage("推送屏幕暂时只支持硬编码,请使用硬件编码。").setTitle("抱歉").show(); new AlertDialog.Builder(this).setMessage("推送屏幕暂时只支持硬编码,请使用硬件编码。").setTitle("抱歉").show();
} else { } else {
onPushScreen(); onPushScreen();
} }
break; break;
default: default:
break; break;
} }
} }
private void startScreenPushIntent() { private void startScreenPushIntent() {
if (StreamActivity.mResultIntent != null && StreamActivity.mResultCode != 0) { if (StreamActivity.mResultIntent != null && StreamActivity.mResultCode != 0) {
RecordService.mEasyIPCamera = new EasyIPCamera(); RecordService.mEasyIPCamera = new EasyIPCamera();
RecordService.mEasyIPCamera.active(getApplicationContext()); RecordService.mEasyIPCamera.active(getApplicationContext());
Intent intent = new Intent(getApplicationContext(), RecordService.class); Intent intent = new Intent(getApplicationContext(), RecordService.class);
startService(intent); startService(intent);
txtStreamAddress.setVisibility(View.VISIBLE); txtStreamAddress.setVisibility(View.VISIBLE);
txtStreamAddress.setText(String.format(getRTSPAddr())); txtStreamAddress.setText(String.format(getRTSPAddr()));
btnPushScreen.setText("停止推送屏幕"); btnPushScreen.setText("停止推送屏幕");
} else { } else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
MediaProjectionManager mMpMngr = (MediaProjectionManager) getApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE); MediaProjectionManager mMpMngr = (MediaProjectionManager) getApplicationContext().getSystemService(MEDIA_PROJECTION_SERVICE);
startActivityForResult(mMpMngr.createScreenCaptureIntent(), StreamActivity.REQUEST_MEDIA_PROJECTION); startActivityForResult(mMpMngr.createScreenCaptureIntent(), StreamActivity.REQUEST_MEDIA_PROJECTION);
} }
} }
} }
public void onPushScreen() { public void onPushScreen() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
new AlertDialog.Builder(this).setMessage("推送屏幕需要安卓5.0以上,您当前系统版本过低,不支持该功能。").setTitle("抱歉").show(); new AlertDialog.Builder(this).setMessage("推送屏幕需要安卓5.0以上,您当前系统版本过低,不支持该功能。").setTitle("抱歉").show();
return; return;
} }
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("alert_screen_background_pushing", false)){ if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("alert_screen_background_pushing", false)){
new AlertDialog.Builder(this).setTitle("提醒").setMessage("屏幕直播将要开始,直播过程中您可以切换到其它屏幕。不过记得直播结束后,再进来停止直播哦!").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { new AlertDialog.Builder(this).setTitle("提醒").setMessage("屏幕直播将要开始,直播过程中您可以切换到其它屏幕。不过记得直播结束后,再进来停止直播哦!").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
PreferenceManager.getDefaultSharedPreferences(StreamActivity.this).edit().putBoolean("alert_screen_background_pushing", true).apply(); PreferenceManager.getDefaultSharedPreferences(StreamActivity.this).edit().putBoolean("alert_screen_background_pushing", true).apply();
onPushScreen(); onPushScreen();
} }
}).show(); }).show();
return; return;
} }
if (RecordService.mEasyIPCamera != null) { if (RecordService.mEasyIPCamera != null) {
Intent intent = new Intent(getApplicationContext(), RecordService.class); Intent intent = new Intent(getApplicationContext(), RecordService.class);
stopService(intent); stopService(intent);
TextView viewById = (TextView) findViewById(R.id.txt_stream_address); TextView viewById = (TextView) findViewById(R.id.txt_stream_address);
viewById.setText(null); viewById.setText(null);
btnPushScreen.setText("推送屏幕"); btnPushScreen.setText("推送屏幕");
btnSwitch.setEnabled(true); btnSwitch.setEnabled(true);
btnSwitchCemera.setEnabled(true); btnSwitchCemera.setEnabled(true);
btnSetting.setEnabled(true); btnSetting.setEnabled(true);
}else{ }else{
btnSwitch.setEnabled(false); btnSwitch.setEnabled(false);
btnSwitchCemera.setEnabled(false); btnSwitchCemera.setEnabled(false);
btnSetting.setEnabled(false); btnSetting.setEnabled(false);
startScreenPushIntent(); startScreenPushIntent();
} }
} }
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_MEDIA_PROJECTION) { if (requestCode == REQUEST_MEDIA_PROJECTION) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Log.e(TAG,"get capture permission success!"); Log.e(TAG,"get capture permission success!");
mResultCode = resultCode; mResultCode = resultCode;
mResultIntent = data; mResultIntent = data;
startScreenPushIntent(); startScreenPushIntent();
} }
} }
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
mMediaStream.destroyChannel(); mMediaStream.destroyChannel();
StatusInfoView.getInstence().uninit(); StatusInfoView.getInstence().uninit();
super.onDestroy(); super.onDestroy();
} }
@Override @Override
protected void onStop() { protected void onStop() {
StatusInfoView.getInstence().uninit(); StatusInfoView.getInstence().uninit();
super.onStop(); super.onStop();
} }
/** /**
* Take care of popping the fragment back stack or finishing the activity * Take care of popping the fragment back stack or finishing the activity
* as appropriate. * as appropriate.
*/ */
@Override @Override
public void onBackPressed() { public void onBackPressed() {
boolean isStreaming = mMediaStream != null && mMediaStream.isOpen(); boolean isStreaming = mMediaStream != null && mMediaStream.isOpen();
if (isStreaming && PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_enable_background_camera", true)){ if (isStreaming && PreferenceManager.getDefaultSharedPreferences(this).getBoolean("key_enable_background_camera", true)){
if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("background_camera_alert", false)){ if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("background_camera_alert", false)){
new AlertDialog.Builder(this).setTitle("提醒").setMessage("您设置了使能摄像头后台采集,因此摄像头将会继续在后台采集并上传视频。记得直播结束后,再回来这里关闭直播。").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { new AlertDialog.Builder(this).setTitle("提醒").setMessage("您设置了使能摄像头后台采集,因此摄像头将会继续在后台采集并上传视频。记得直播结束后,再回来这里关闭直播。").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
PreferenceManager.getDefaultSharedPreferences(StreamActivity.this).edit().putBoolean("background_camera_alert", true).apply(); PreferenceManager.getDefaultSharedPreferences(StreamActivity.this).edit().putBoolean("background_camera_alert", true).apply();
StreamActivity.super.onBackPressed(); StreamActivity.super.onBackPressed();
} }
}).show(); }).show();
return; return;
} }
super.onBackPressed(); super.onBackPressed();
}else{ }else{
super.onBackPressed(); super.onBackPressed();
} }
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册