Skip to content

Commit

Permalink
Merge pull request #68 from ksvc/updateVer_to_1.4.6
Browse files Browse the repository at this point in the history
update ver to 1.4.6
  • Loading branch information
chriszeng87 authored Oct 17, 2017
2 parents 85e746b + addc246 commit afe6768
Show file tree
Hide file tree
Showing 21 changed files with 401 additions and 77 deletions.
12 changes: 6 additions & 6 deletions demo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.ksyun.media.shortvideo.demo"
minSdkVersion 19
targetSdkVersion 24
versionCode 142
versionName "1.4.2"
versionCode 146
versionName "1.4.6"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
Expand Down Expand Up @@ -40,8 +40,8 @@ dependencies {
compile 'com.facebook.fresco:fresco:1.4.0'
compile 'com.facebook.fresco:animated-gif:1.4.0'
compile 'com.facebook.fresco:animated-webp:1.4.0'
compile 'com.ksyun.media:libksysv-java:1.4.2'
compile 'com.ksyun.media:libksysv-arm64:1.4.2'
compile 'com.ksyun.media:libksysv-armv7a:1.4.2'
compile 'com.ksyun.media:libksysv-x86:1.4.2'
compile 'com.ksyun.media:libksysv-java:1.4.6'
compile 'com.ksyun.media:libksysv-arm64:1.4.6'
compile 'com.ksyun.media:libksysv-armv7a:1.4.6'
compile 'com.ksyun.media:libksysv-x86:1.4.6'
}
1 change: 1 addition & 0 deletions demo/app/src/main/assets/AuthForTest.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
h1iuRSzMW60Iwm2XzBzu40UnPMP4Td2X2Ab5JAKtfDD3kzmND4Hc6McUvbtvI+TVSRmMsXYCynqIqMnlzLtS+srE1B4bkh4ZQ5GxVttDe2ldWspDUxwBdEk+8fI3l11UhZXZZh2XEoJ2reqytoneKQbVIqt7UrZFd4Wx9a6Tpp4=SZs8qatUU89FFTWMLWeM6KFxtsJOI2dS6COArBPYvrzJEVfVRk/2u80JsfX+JrvuGY6yTs/SMw6lTqZF0zcB67na0znaGd0ahfeRKm0dihOMjk9BtTmeWk4HH5i64rM8/7r/bh2NIRZGICsgpJzKW5w7wBLH3GHo7vmaiDblj60=
Original file line number Diff line number Diff line change
Expand Up @@ -1543,6 +1543,8 @@ public void onClick(View view) {
mOutForGIF.setActivated(false);
mOutEncodeWithH264.setEnabled(true);
mOutEncodeWithH265.setEnabled(true);
mOutEncodeWithH264.setActivated(true);
mOutEncodeWithH265.setActivated(false);
mOutEncodeByHW.setEnabled(true);
break;
case R.id.output_config_gif:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.ksyun.media.shortvideo.demo.adapter.MediaGalleryAdapter;
import com.ksyun.media.shortvideo.demo.adapter.MediaSelectedAdapter;
Expand Down Expand Up @@ -114,10 +115,14 @@ private void onSelectedDataConfirmed() {
for (int i = 0; i < list.size(); i++) {
path.add(list.get(i).filePath);
}
Intent intent = new Intent();
intent.putStringArrayListExtra("filePath", path);
setResult(RESULT_CODE, intent);
finish();
if (path.size() == 0) {
Toast.makeText(this, "请至少选择一个文件", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent();
intent.putStringArrayListExtra("filePath", path);
setResult(RESULT_CODE, intent);
finish();
}
}

private class ButtonObserver implements View.OnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.ksyun.media.shortvideo.kit.KSYEditKit;
import com.ksyun.media.shortvideo.utils.AuthInfoManager;

import org.apache.http.util.EncodingUtils;
import org.json.JSONException;
import org.json.JSONObject;

Expand All @@ -12,6 +13,7 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
Expand All @@ -22,6 +24,8 @@
import android.widget.TextView;
import android.widget.Toast;

import java.io.InputStream;

/**
* 引导窗口页
*/
Expand Down Expand Up @@ -79,7 +83,7 @@ private void showWebView() {
mDefaultView.setVisibility(View.GONE);
mWebView.setVisibility(View.VISIBLE);
mWebView.loadUrl(COLOPHON_URL);
mWebView.setWebViewClient(new WebViewClient(){
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
Expand All @@ -102,7 +106,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
default:
break;
}
return super.onKeyDown(keyCode,event);
return super.onKeyDown(keyCode, event);
}

@Override
Expand All @@ -122,73 +126,117 @@ public void onDestroy() {
AuthInfoManager.getInstance().removeAuthResultListener(mCheckAuthResultListener);
}


/**
* SDK鉴权
*/
private void checkAuth() {
String token = null;
try {
InputStream in = getResources().getAssets().open("AuthForTest.pkg");

if (mAuthResponse == null) {
mAuthResponse = new HttpRequestTask.HttpResponseListener() {
@Override
public void onHttpResponse(int responseCode, String response) {
//params response
boolean authResult = false;
if (responseCode == 200) {
try {
JSONObject temp = new JSONObject(response);
JSONObject data = temp.getJSONObject("Data");
int result = data.getInt("RetCode");
if (result == 0) {
String authInfo = data.getString("Authorization");
String date = data.getString("x-amz-date");
//初始化鉴权信息
AuthInfoManager.getInstance().setAuthInfo(authInfo, date);
//添加鉴权结果回调接口(不是必须)
AuthInfoManager.getInstance().addAuthResultListener(mCheckAuthResultListener);
//开始向KSServer申请鉴权
AuthInfoManager.getInstance().checkAuth();
authResult = true;
} else {
Log.e(TAG, "get auth failed from app server RetCode:" + result);
}
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, "get auth failed from app server json parse failed");
}
} else {
Log.e(TAG, "get auth failed from app server responseCode:" + responseCode);
}
int length = in.available();

final boolean finalAuthResult = authResult;
runOnUiThread(new Runnable() {
byte[] buffer = new byte[length];

in.read(buffer);

token = EncodingUtils.getString(buffer, "UTF-8");

} catch (Exception e) {
e.printStackTrace();
}

if (!TextUtils.isEmpty(token)) {
AuthInfoManager.getInstance().setAuthInfo(token);
AuthInfoManager.getInstance().checkAuth();
if (AuthInfoManager.getInstance().getAuthState()) {
Toast.makeText(ShortVideoActivity.this, "Auth Success", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(ShortVideoActivity.this, "Auth Failed", Toast.LENGTH_SHORT)
.show();
}
} else {
AuthInfoManager.getInstance().addAuthResultListener(new AuthInfoManager.CheckAuthResultListener() {
@Override
public void onAuthResult(int i) {
mMainHandler.post(new Runnable() {
@Override
public void run() {
if (!finalAuthResult) {
Toast.makeText(ShortVideoActivity.this, "get auth failed from app " +
"server", Toast.LENGTH_SHORT)
AuthInfoManager.getInstance().removeAuthResultListener(mCheckAuthResultListener);
if (AuthInfoManager.getInstance().getAuthState()) {
Toast.makeText(ShortVideoActivity.this, "Auth Success", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(ShortVideoActivity.this, "Auth Failed", Toast.LENGTH_SHORT)
.show();
//鉴权失败,尝试3次
if (mRetryCount < MAX_RETRY_COUNT) {
mRetryCount++;
checkAuth();
}
}
}
});
}
};
}
});
if (mAuthResponse == null) {
mAuthResponse = new HttpRequestTask.HttpResponseListener() {
@Override
public void onHttpResponse(int responseCode, String response) {
//params response
boolean authResult = false;
if (responseCode == 200) {
try {
JSONObject temp = new JSONObject(response);
JSONObject data = temp.getJSONObject("Data");
int result = data.getInt("RetCode");
if (result == 0) {
String authInfo = data.getString("Authorization");
String date = data.getString("x-amz-date");
//初始化鉴权信息
AuthInfoManager.getInstance().setAuthInfo(authInfo, date);
//添加鉴权结果回调接口(不是必须)
AuthInfoManager.getInstance().addAuthResultListener(mCheckAuthResultListener);
//开始向KSServer申请鉴权
AuthInfoManager.getInstance().checkAuth();
authResult = true;
} else {
Log.e(TAG, "get auth failed from app server RetCode:" + result);
}
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, "get auth failed from app server json parse failed");
}
} else {
Log.e(TAG, "get auth failed from app server responseCode:" + responseCode);
}

if (mAuthTask != null && mAuthTask.getStatus() != AsyncTask.Status.FINISHED) {
mAuthTask.cancel(true);
mAuthTask = null;
final boolean finalAuthResult = authResult;
runOnUiThread(new Runnable() {
@Override
public void run() {
if (!finalAuthResult) {
Toast.makeText(ShortVideoActivity.this, "get auth failed from app " +
"server", Toast.LENGTH_SHORT)
.show();
//鉴权失败,尝试3次
if (mRetryCount < MAX_RETRY_COUNT) {
mRetryCount++;
checkAuth();
}
}
}
});
}
};
}

if (mAuthTask != null && mAuthTask.getStatus() != AsyncTask.Status.FINISHED) {
mAuthTask.cancel(true);
mAuthTask = null;
}
//开启异步任务,向AppServer请求鉴权信息
mAuthTask = new HttpRequestTask(mAuthResponse);
String url = AUTH_SERVER_URI + "?Pkg=" + getApplicationContext().getPackageName();
Log.d(TAG, "request auth:" + url);
mAuthTask.execute(url);
}
//开启异步任务,向AppServer请求鉴权信息
mAuthTask = new HttpRequestTask(mAuthResponse);
String url = AUTH_SERVER_URI + "?Pkg=" + getApplicationContext().getPackageName();
Log.d(TAG, "request auth:" + url);
mAuthTask.execute(url);
}

private AuthInfoManager.CheckAuthResultListener mCheckAuthResultListener = new AuthInfoManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public RecordProgressController(RecordProgressView view, Chronometer cmt) {
private class ChangeProgressRunnable implements Runnable {
@Override
public void run() {
if (getChronometerTime() >= RecordActivity.MAX_DURATION) {
if (getTotalRecordTime() >= RecordActivity.MAX_DURATION) {
mProgressView.invalidate();
if (mIsRecording && mRecordingLengthChangedListener != null) {
mRecordingLengthChangedListener.passMaxPoint();
Expand Down Expand Up @@ -83,6 +83,14 @@ public int getChronometerTime() {
return curTime * 1000;
}

private long getTotalRecordTime() {
long time = 0;
for (RecordClipModel clip : mProgressClipList) {
time += clip.timeInterval;
}
return time;
}

/**
* 是否到达了最小录制时长
*
Expand Down
3 changes: 2 additions & 1 deletion demo/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Fri May 19 20:52:25 CST 2017
#Thu May 18 16:03:35 CST 2017

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Loading

0 comments on commit afe6768

Please sign in to comment.