提交 a92e884e 编写于 作者: K kidloserme

add new Proj

上级 ff191841
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "org.easydarwin.easyplayer"
minSdkVersion 16
targetSdkVersion 21
versionCode 4
versionName "1.0.16.0618"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile(name: 'rtspclient-release', ext: 'aar')
compile project(':okhttplibrary')
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'org.greenrobot:eventbus:3.0.0'
compile 'com.umeng.analytics:analytics:latest.integration'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\AndroidStudio\StudioSDK/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
package org.easydarwin.easyplayer;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.easydarwin.easyplayer">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:name="org.easydarwin.easyplayer.MyApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="org.easydarwin.easyplayer.activity.MainActivity"
android:screenOrientation="portrait" />
<activity
android:name="org.easydarwin.easyplayer.activity.SplashActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="org.easydarwin.easyplayer.activity.SettingActivity"
android:screenOrientation="portrait" />
<activity
android:name="org.easydarwin.easyplayer.activity.EasyPlayerActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
/>
<activity android:name="org.easydarwin.easyplayer.activity.AddLocalSessionActivity"
android:screenOrientation="portrait"/>
</application>
</manifest>
\ No newline at end of file
/*
* Copyright (c) 2013-2016 EasyDarwin.ORG. All rights reserved.
* Github: https://github.com/EasyDarwin
* WEChat: EasyDarwin
* Website: http://www.easydarwin.org
*/
package org.easydarwin.easyplayer;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.text.TextUtils;
import org.easydarwin.easyplayer.config.DarwinConfig;
import org.easydarwin.okhttplibrary.OkHttpUtils;
import java.util.concurrent.TimeUnit;
/**
* Created by zhy on 15/8/25.
*/
public class MyApplication extends Application
{
private static MyApplication instance;
@Override
public void onCreate()
{
super.onCreate();
OkHttpUtils.getInstance().setConnectTimeout(100000, TimeUnit.MILLISECONDS);
instance=this;
initServerInfo();
}
private void initServerInfo(){
SharedPreferences sharedPreferences = getSharedPreferences(DarwinConfig.SETTING_PREF_NAME, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
String serverIp = sharedPreferences.getString(DarwinConfig.SERVER_IP, "");
if (TextUtils.isEmpty(serverIp)) {
editor.putString(DarwinConfig.SERVER_IP, DarwinConfig.DEFAULT_SERVER_IP);
editor.commit();
}
String port = sharedPreferences.getString(DarwinConfig.SERVER_PORT, "");
if (TextUtils.isEmpty(port)) {
editor.putString(DarwinConfig.SERVER_PORT, DarwinConfig.DEFAULT_SERVER_PORT);
editor.commit();
}
}
/**
* @return the main context of the Application
*/
public static Context getAppContext()
{
return instance;
}
public static Resources getAppResources()
{
return instance.getResources();
}
}
package org.easydarwin.easyplayer.activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import org.easydarwin.easyplayer.R;
import org.easydarwin.easyplayer.config.DarwinConfig;
import org.easydarwin.easyplayer.domain.LocalAddSessionVO;
import org.easydarwin.easyplayer.event.LocalSessionEvent;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
import java.util.UUID;
public class AddLocalSessionActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar=getSupportActionBar();
if(actionBar!=null){
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setTitle(R.string.title_activity_add_session);
actionBar.show();
}
setContentView(R.layout.activity_add_local_session);
final List<LocalAddSessionVO> localAddSessions = getMyLocalSession();
final EditText txtName= (EditText) findViewById(R.id.edt_name);
txtName.setText(String.valueOf(System.currentTimeMillis()));
final EditText txtUrl= (EditText) findViewById(R.id.edt_url);
final LocalAddSessionVO intentSession= (LocalAddSessionVO) getIntent().getSerializableExtra(DarwinConfig.SESSION_DATA);
if(intentSession!=null){
txtName.setText(intentSession.getName());
txtUrl.setText(intentSession.getAddress());
}
findViewById(R.id.btn_save).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name=txtName.getText().toString();
String url=txtUrl.getText().toString();
if(TextUtils.isEmpty(url)){
Toast.makeText(AddLocalSessionActivity.this,"请输入直播地址",Toast.LENGTH_LONG).show();
return;
}
if(!url.startsWith("rtsp://") || !url.endsWith(".sdp") || url.equals("rtsp://.sdp")){
Toast.makeText(AddLocalSessionActivity.this,"请输入正确的直播地址",Toast.LENGTH_LONG).show();
return;
}
if(intentSession!=null){
intentSession.setName(name);
intentSession.setAddress(url);
for (int i=0;i<localAddSessions.size();i++){
if(intentSession.getId().equals(localAddSessions.get(i).getId())){
localAddSessions.set(i,intentSession);
break;
}
}
}else {
LocalAddSessionVO localAddSessionVO=new LocalAddSessionVO();
String id= UUID.randomUUID().toString();
localAddSessionVO.setAddress(url);
localAddSessionVO.setName(name);
localAddSessionVO.setId(id);
localAddSessions.add(localAddSessionVO);
}
saveMyLocalSessions(LocalAddSessionVO.toJson(localAddSessions));
LocalSessionEvent localSessionEvent = new LocalSessionEvent();
localSessionEvent.setLocalAddSessionVOs(localAddSessions);
EventBus.getDefault().post(localSessionEvent);
finish();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case android.R.id.home:
finish();
break;
}
return super.onOptionsItemSelected(item);
}
}
/*
Copyright (c) 2013-2016 EasyDarwin.ORG. All rights reserved.
Github: https://github.com/EasyDarwin
WEChat: EasyDarwin
Website: http://www.easydarwin.org
*/
package org.easydarwin.easyplayer.activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
import org.easydarwin.easyplayer.config.DarwinConfig;
import org.easydarwin.easyplayer.domain.LocalAddSessionVO;
import org.easydarwin.easyplayer.indicator.WaitProgressDialog;
import java.util.List;
/**
* 类BaseActivity的实现描述://TODO 类实现描述
*
* @author HELONG 2016/3/16 18:06
*/
public class BaseActivity extends AppCompatActivity {
static SharedPreferences mSettingSharedPreference;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(mSettingSharedPreference==null){
mSettingSharedPreference=getSharedPreferences(DarwinConfig.SETTING_PREF_NAME,MODE_PRIVATE);
}
}
protected void showToadMessage(String message){
Toast.makeText(this,message,Toast.LENGTH_LONG).show();
}
private WaitProgressDialog waitProgressDialog;
// 显示等待框
public void showWaitProgress(String message) {
if (waitProgressDialog == null) {
waitProgressDialog = new WaitProgressDialog(this);
}
waitProgressDialog.showProgress(message);
}
// 隐藏等待框
public void hideWaitProgress() {
if (waitProgressDialog != null) {
waitProgressDialog.hideProgress();
}
}
protected List<LocalAddSessionVO> getMyLocalSession(){
String localString=mSettingSharedPreference.getString(DarwinConfig.LOCAL_SESSION,DarwinConfig.LOCAL_SESSION_DEFAUT);
return LocalAddSessionVO.parse(localString);
}
protected void saveMyLocalSessions(String json){
SharedPreferences.Editor editor = mSettingSharedPreference.edit();
editor.putString(DarwinConfig.LOCAL_SESSION,json);
editor.commit();
}
}
package org.easydarwin.easyplayer.activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.ViewConfigurationCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Toast;
import org.easydarwin.easyplayer.R;
import org.easydarwin.easyplayer.config.DarwinConfig;
import org.easydarwin.video.EasyRTSPClient;
import org.easydarwin.video.RTSPClient;
public class EasyPlayerActivity extends AppCompatActivity implements SurfaceHolder.Callback {
private String mRTSPUrl;
private EasyRTSPClient mStreamRender;
private ResultReceiver mResultReceiver;
private GestureDetectorCompat mDetector;
private int mWidth;
private int mHeight;
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
private static final String DEBUG_TAG = "Gestures";
@Override
public boolean onDown(MotionEvent event) {
return true;
}
@Override
public boolean onDoubleTap(MotionEvent motionEvent) {
setRequestedOrientation((getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT) ?
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
return true;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
mRTSPUrl = getIntent().getStringExtra(DarwinConfig.RTSP_ADDRESS);
if (TextUtils.isEmpty(mRTSPUrl)) {
finish();
return;
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
if (isLandscape()) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
setContentView(R.layout.activity_easyplayer);
final SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view);
surfaceView.getHolder().addCallback(this);
mDetector = new GestureDetectorCompat(this, new MyGestureListener());
mResultReceiver = new ResultReceiver(new Handler()) {
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
super.onReceiveResult(resultCode, resultData);
if (resultCode == EasyRTSPClient.RESULT_VIDEO_DISPLAYED) {
findViewById(android.R.id.progress).setVisibility(View.GONE);
} else if (resultCode == EasyRTSPClient.RESULT_VIDEO_SIZE) {
mWidth = resultData.getInt(EasyRTSPClient.EXTRA_VIDEO_WIDTH);
mHeight = resultData.getInt(EasyRTSPClient.EXTRA_VIDEO_HEIGHT);
if (!isLandscape()) {
fixPlayerRatio(surfaceView, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
}
} else if (resultCode == EasyRTSPClient.RESULT_TIMEOUT) {
Toast.makeText(EasyPlayerActivity.this, "试播时间到", Toast.LENGTH_SHORT).show();
}
}
};
}
private void fixPlayerRatio(View renderView, int maxWidth, int maxHeight) {
int widthSize = maxWidth;
int heightSize = maxHeight;
int width = mWidth, height = mHeight;
float aspectRatio = width * 1.0f / height;
if (widthSize > heightSize * aspectRatio) {
height = heightSize;
width = (int) (height * aspectRatio);
} else {
width = widthSize;
height = (int) (width / aspectRatio);
}
renderView.getLayoutParams().width = width;
renderView.getLayoutParams().height = height;
renderView.requestLayout();
}
private boolean isLandscape() {
return getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return mDetector.onTouchEvent(event);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
final View render = findViewById(R.id.surface_view);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
setNavVisibility(true);
final ViewGroup.LayoutParams params = render.getLayoutParams();
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
render.requestLayout();
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
fixPlayerRatio(render, getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels);
setNavVisibility(false);
}
}
public void setNavVisibility(boolean visible) {
if (!ViewConfigurationCompat.hasPermanentMenuKey(ViewConfiguration.get(this))) {
int newVis = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
if (!visible) {
newVis |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
}
getWindow().getDecorView().setSystemUiVisibility(newVis);
}
}
public void onResume() {
super.onResume();
}
public void onPause() {
super.onPause();
}
@Override
public void surfaceCreated(final SurfaceHolder surfaceHolder) {
startRending(surfaceHolder.getSurface());
}
private void startRending(Surface surface) {
mStreamRender = new EasyRTSPClient(this, "F94CAB947C2786773C95DC05244DF8CA", surface, mResultReceiver);
mStreamRender.start(1, mRTSPUrl, RTSPClient.TRANSTYPE_TCP, RTSPClient.EASY_SDK_VIDEO_FRAME_FLAG | RTSPClient.EASY_SDK_AUDIO_FRAME_FLAG, "admin", "admin");
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {
}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
if (mStreamRender != null) {
mStreamRender.stop();
mStreamRender = null;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
return super.onCreateOptionsMenu(menu);
}