Skip to content

Commit

Permalink
Merge pull request #55 from ksvc/updateVer_1.2.2
Browse files Browse the repository at this point in the history
update ver to 1.2.2
  • Loading branch information
chriszeng87 authored Aug 25, 2017
2 parents 1382748 + e301c0a commit ed17ab9
Show file tree
Hide file tree
Showing 72 changed files with 18,274 additions and 1,232 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 15
targetSdkVersion 24
versionCode 112
versionName "1.1.2"
versionCode 122
versionName "1.2.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
Expand All @@ -35,8 +35,8 @@ dependencies {
compile 'com.tencent.bugly:nativecrashreport:latest.release'
compile 'com.ksyun.mc:libkmcfilter_sensetime:1.0.4'
compile 'com.ksyun.mc:SenseTimeAR:1.0.4'
compile 'com.ksyun.media:libksysv-java:1.1.2'
compile 'com.ksyun.media:libksysv-arm64:1.1.2'
compile 'com.ksyun.media:libksysv-armv7a:1.1.2'
compile 'com.ksyun.media:libksysv-x86:1.1.2'
compile 'com.ksyun.media:libksysv-java:1.2.2'
compile 'com.ksyun.media:libksysv-arm64:1.2.2'
compile 'com.ksyun.media:libksysv-armv7a:1.2.2'
compile 'com.ksyun.media:libksysv-x86:1.2.2'
}

Large diffs are not rendered by default.

587 changes: 388 additions & 199 deletions demo/app/src/main/java/com/ksyun/media/shortvideo/demo/EditActivity.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
Expand Down Expand Up @@ -32,7 +31,6 @@
import com.ksyun.ks3.services.handler.PutObjectResponseHandler;
import com.ksyun.media.player.IMediaPlayer;
import com.ksyun.media.player.KSYMediaPlayer;
import com.ksyun.media.player.misc.KSYProbeMediaInfo;
import com.ksyun.media.shortvideo.demo.util.HttpRequestTask;
import com.ksyun.media.shortvideo.demo.util.KS3TokenTask;
import com.ksyun.media.shortvideo.utils.FileUtils;
Expand All @@ -48,7 +46,7 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicInteger;

public class PublishActivity extends Activity {
//获取ks3播放地址,仅供demo使用,不提供上线服务
Expand All @@ -58,6 +56,11 @@ public class PublishActivity extends Activity {
public static final String MIME_TYPE = "mime_type";
public static final String PREVIEW_LEN = "preview_length";

//标记上传状态
private static final int UPLOAD_STATE_NONE = 0;
private static final int UPLOAD_STATE_STARTING = 1;
private static final int UPLOAD_STATE_STARTED = 2;

private View mPreviewLayout; //上传后的预览布局
private View mCoverSeekLayout; //封面选择布局
private ImageView mCoverBack;
Expand All @@ -77,7 +80,7 @@ public class PublishActivity extends Activity {
private volatile Bitmap mBitmap; //视频封面
private long mSeekTime;
private Timer mSeekTimer;
private float mPreviewLength; //视频预览时长
private long mPreviewLength; //视频预览时长
private ButtonObserver mButtonObserver;
private ProbeMediaInfoTools mImageSeekTools; //根据时间获取视频帧的工具类
private Handler mMainHandler;
Expand All @@ -92,18 +95,21 @@ public class PublishActivity extends Activity {
private Handler mSeekThumbnailHandler;
private Runnable mSeekThumbnailRunable;
private volatile boolean mStopSeekThumbnail = true;
private volatile boolean mH265File = false;

/*****合成窗口View*****/
private TextView mStateTextView;
private TextView mProgressText; //显示上传进度
private PopupWindow mUploadWindow; //上传状态的显示窗口
private View mParentView;

private AtomicInteger mUploadState; //上传ks3状态

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_publish);
mParentView = LayoutInflater.from(this).inflate(R.layout.activity_publish, null);
//must set
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
Expand All @@ -113,7 +119,7 @@ protected void onCreate(Bundle savedInstanceState) {
mFilePath = mLocalPath;
mMainHandler = new Handler();
mFileMineType = getIntent().getExtras().getString(MIME_TYPE);
mPreviewLength = getIntent().getExtras().getFloat(PREVIEW_LEN);
mPreviewLength = getIntent().getExtras().getLong(PREVIEW_LEN);
mPreviewLayout = findViewById(R.id.compose_preview_layout);
mCoverSeekLayout = findViewById(R.id.cover_layout);
mButtonObserver = new ButtonObserver();
Expand All @@ -131,14 +137,13 @@ protected void onCreate(Bundle savedInstanceState) {
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mSurfaceHolder = mVideoSurfaceView.getHolder();
mSurfaceHolder.addCallback(mSurfaceCallback);
if (!mFileMineType.equals(FileUtils.MINE_TYPE_GIF)) {
mUploadState = new AtomicInteger(UPLOAD_STATE_NONE);
if (!mFileMineType.equals(FileUtils.MIME_TYPE_GIF)) {
startCoverSeek();
} else {
mCoverSeekLayout.setVisibility(View.GONE);
startUpload(); //若为gif则不选择封面直接上传
}


}

private void initSeekThread() {
Expand All @@ -155,14 +160,16 @@ public void handleMessage(Message msg) {
mSeekThumbnailRunable = new Runnable() {
@Override
public void run() {
if (!mH265File) {
mBitmap = mImageSeekTools.getVideoThumbnailAtTime(mLocalPath, mSeekTime,
0, 0, true);
} else {
//h265的视频暂时不支持精准seek
mBitmap = mImageSeekTools.getVideoThumbnailAtTime(mLocalPath, mSeekTime,
0, 0, false);
if (mSeekTime < 0) {
mSeekTime = 0;
}

if (mSeekTime > mPreviewLength) {
mSeekTime = mPreviewLength;
}

mBitmap = mImageSeekTools.getVideoThumbnailAtTime(mLocalPath, mSeekTime,
0, 0, true);
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -192,6 +199,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
@Override
protected void onDestroy() {
releasePlay();

if (mPlayUrlGetTask != null) {
mPlayUrlGetTask.cancel(true);
mPlayUrlGetTask.release();
Expand Down Expand Up @@ -219,21 +227,6 @@ protected void onDestroy() {
}

private void startCoverSeek() {
//h265的视频暂时不支持精准获取缩略图
ProbeMediaInfoTools tools = new ProbeMediaInfoTools();
tools.probeMediaInfo(mLocalPath, new ProbeMediaInfoTools.ProbeMediaInfoListener() {
@Override
public void probeMediaInfoFinished(ProbeMediaInfoTools.MediaInfo info) {
if (info.videoStreams != null && info.videoStreams.size() > 0) {
KSYProbeMediaInfo.KSYVideoCodecType videoCodecType = info.videoStreams.get(0)
.getVideoCodecType();
if (videoCodecType == KSYProbeMediaInfo.KSYVideoCodecType.KSY_VIDEO_H265) {
mH265File = true;
}
}
}
});

mCoverBack = (ImageView) findViewById(R.id.cover_back);
mCoverBack.setOnClickListener(mButtonObserver);
mCoverComplete = (TextView) findViewById(R.id.cover_complete);
Expand All @@ -242,6 +235,15 @@ public void probeMediaInfoFinished(ProbeMediaInfoTools.MediaInfo info) {
mCoverSeekBar = (AppCompatSeekBar) findViewById(R.id.cover_seekBar);
mImageSeekTools = new ProbeMediaInfoTools();
mBitmap = mImageSeekTools.getVideoThumbnailAtTime(mLocalPath, mSeekTime, 0, 0, true);

mImageSeekTools.probeMediaInfo(mLocalPath, new ProbeMediaInfoTools.ProbeMediaInfoListener() {
@Override
public void probeMediaInfoFinished(ProbeMediaInfoTools.MediaInfo info) {
//使用合成视频时长更新视频的时长
mPreviewLength = info.duration;
}
});

mCoverImage.setImageBitmap(mBitmap);
mCoverSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
Expand Down Expand Up @@ -289,6 +291,14 @@ public void onClick(View v) {
}

private void onBackClick() {
if (mUploadState.get() >= UPLOAD_STATE_STARTING && mUploadState.get() <=
UPLOAD_STATE_STARTED) {
//取消上传,直接预览播放本地视频
mKS3Wrap.cancel();
onUploadFinished(false);
return;
}

Intent intent = new Intent(PublishActivity.this, ConfigActivity.class);
startActivity(intent);
}
Expand All @@ -300,12 +310,13 @@ private void onPublishClick() {
private void startUpload() {
mKS3Wrap = KS3ClientWrap.getInstance(getApplicationContext());
if (!TextUtils.isEmpty(mLocalPath)) {
mUploadState.set(UPLOAD_STATE_STARTING);
String mineType = FileUtils.getMimeType(new File(mLocalPath));
StringBuilder objectKey = new StringBuilder(getPackageName() +
"/" + System.currentTimeMillis());
if (mineType == FileUtils.MINE_TYPE_MP4) {
if (mineType == FileUtils.MIME_TYPE_MP4) {
objectKey.append(".mp4");
} else if (mineType == FileUtils.MINE_TYPE_GIF) {
} else if (mineType == FileUtils.MIME_TYPE_GIF) {
objectKey.append(".gif");
}
mCurObjectKey = objectKey.toString();
Expand Down Expand Up @@ -354,11 +365,13 @@ public void onTaskStart() {
@Override
public void onTaskFinish() {
Log.d(TAG, "onTaskFinish");
mUploadState.set(UPLOAD_STATE_NONE);
}

@Override
public void onTaskCancel() {
Log.d(TAG, "onTaskCancel");
mUploadState.set(UPLOAD_STATE_NONE);
}

@Override
Expand All @@ -368,6 +381,7 @@ public void onTaskProgress(double progress) {
};

private void onUploadStart() {
mUploadState.set(UPLOAD_STATE_STARTED);
resetPlay();
showUploadProgressDialog();
}
Expand All @@ -384,6 +398,7 @@ public void run() {
}

private void onUploadFinished(final boolean success) {
mUploadState.set(UPLOAD_STATE_NONE);
runOnUiThread(new Runnable() {
@Override
public void run() {
Expand Down Expand Up @@ -413,7 +428,7 @@ public void onHttpResponse(int responseCode, String response) {
url = "http://" + url;
}
mFilePath = url;
Log.e(TAG, "play url:" + mFilePath);
Log.d(TAG, "play url:" + mFilePath);
startPreview();
}
} catch (JSONException e) {
Expand All @@ -429,28 +444,28 @@ public void onHttpResponse(int responseCode, String response) {
mStateTextView.setText(R.string.get_file_url);
mPlayUrlGetTask.execute(FILE_URL_SERVER + "?objkey=" + mCurObjectKey);
} else {
mStateTextView.setVisibility(View.VISIBLE);
mStateTextView.setText(R.string.upload_file_fail);
if (mStateTextView != null) {
mStateTextView.setVisibility(View.VISIBLE);
mStateTextView.setText(R.string.upload_file_fail);
}
startPreview();
}

}
});
}

private void showUploadProgressDialog() {
View contentView = LayoutInflater.from(this).inflate(R.layout.compose_layout, null);
mStateTextView = (TextView) contentView.findViewById(R.id.state_text);
mProgressText = (TextView) contentView.findViewById(R.id.progress_text);
mStateTextView.setText(R.string.upload_file);

if (mUploadWindow == null) {
View contentView = LayoutInflater.from(this).inflate(R.layout.compose_layout, null);
mStateTextView = (TextView) contentView.findViewById(R.id.state_text);
mProgressText = (TextView) contentView.findViewById(R.id.progress_text);
mStateTextView.setText(R.string.upload_file);
mUploadWindow = new PopupWindow(contentView, WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT);
}

if (!mUploadWindow.isShowing()) {
View parent = LayoutInflater.from(this).inflate(R.layout.activity_publish, null);
mUploadWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
mUploadWindow.showAtLocation(mParentView, Gravity.CENTER, 0, 0);
}
}

Expand Down Expand Up @@ -508,10 +523,11 @@ private void startPreview() {
@Override
public void run() {
Log.d(TAG, "start compose file Preview:");
if (mFileMineType.equals(FileUtils.MINE_TYPE_GIF)) {
if (mUploadWindow != null && mUploadWindow.isShowing()) {
mUploadWindow.dismiss();
}
if (mUploadWindow != null && mUploadWindow.isShowing()) {
mUploadWindow.dismiss();
}

if (mFileMineType.equals(FileUtils.MIME_TYPE_GIF)) {
mPreviewLayout.setVisibility(View.VISIBLE);
mGifView.setVisibility(View.VISIBLE);
mGifView.loadUrl("file://" + mLocalPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,12 @@ public void run() {
dialog.dismiss();
mRecordUrl = filePath; //合成文件本地路径
updateRecordUI();
if (filePath == null) {
Log.e(TAG, "Merge file failed");
Toast.makeText(RecordActivity.this, "Merge file failed!",
Toast.LENGTH_LONG).show();
return;
}
//可以调用此接口在合成结束后,删除断点录制的所有视频
//mKSYRecordKit.deleteAllFiles();

Expand Down Expand Up @@ -842,8 +848,14 @@ public void onProgressChanged(VerticalSeekBar seekBar, int progress, boolean fro
if (parameters != null) {
int minValue = parameters.getMinExposureCompensation();
int maxValue = parameters.getMaxExposureCompensation();
int range = 100 / (maxValue - minValue);
parameters.setExposureCompensation(progress / range + minValue);
int range = 0;
int value = minValue;
if (maxValue > minValue) {
range = 100 / (maxValue - minValue);
value = progress / range + minValue;
}

parameters.setExposureCompensation(value);
}
mKSYRecordKit.getCameraCapture().setCameraParameters(parameters);
}
Expand Down Expand Up @@ -928,12 +940,14 @@ public void onCancel() {
}

@Override
public void onSelected(String path) {
if(ViewUtils.isForeground(RecordActivity.this, RecordActivity.class.getName())) {
public boolean onSelected(String path) {
if (ViewUtils.isForeground(RecordActivity.this, RecordActivity.class.getName())) {
setEnableBgmEdit(true);
clearPitchState();
mKSYRecordKit.startBgm(path, true);
return true;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class ShortVideoConfig {
public int encodeMethod = StreamerConstants.ENCODE_METHOD_SOFTWARE;
public int encodeProfile = VideoEncodeFormat.ENCODE_PROFILE_LOW_POWER;
public int videoCRF = 24;
public int audioChannel = 1;
public int audioSampleRate = 44100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class BgmSelectAdapter extends RecyclerView.Adapter<BgmSelectAdapter.MyVi
public interface OnItemClickListener {
void onCancel();

void onSelected(String path);
boolean onSelected(String path);

void onImport();
}
Expand Down Expand Up @@ -115,9 +115,11 @@ public void onCompleted(String downloadFilePath) {

if (!TextUtils.isEmpty(mCurrentFilePath) && mCurrentFilePath.equals
(downloadFilePath)) {
holder.setActivated(true);
if (mListener != null) {
mListener.onSelected(mCurrentFilePath);
boolean isShow = mListener.onSelected(mCurrentFilePath);
if(isShow) {
holder.setActivated(true);
}
}
}
}
Expand Down Expand Up @@ -160,7 +162,6 @@ public void clear() {
mPreHolder.mProgress.setVisibility(View.GONE);
mPreHolder.setActivated(false);
}
clearTask();
}

public void clearTask() {
Expand Down
Loading

0 comments on commit ed17ab9

Please sign in to comment.