Commit eb84ed53 by Lee Munkyeong

動画エンコード実装

parent d8023f43
......@@ -792,12 +792,12 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
return;
}
/*mChatWebView.post(new Runnable() {
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.showLoadingIndicator();");
}
});*/
});
if (dataUri != null) {
Cursor cursor = getContentResolver().query(dataUri, null, null, null, null);
......@@ -807,28 +807,27 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
cursor.close();
Runnable r = new Runnable() {
@Override
public void run() {
try {
//CallBack
Runnable callBack = new Runnable() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.videoEncodeEnd('" +encodedFilePath + "')");
}
});
}
};
Context c = getApplicationContext();
File file = new File(filePath);
String encodedPath = new VideoEncoder().changeResolution(file);
String encodedPath = new VideoEncoder().changeResolution(file, callBack);
encodedFilePath = encodedPath;
final Uri _uri = getImageContentUri(c, new File(encodedPath));
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, _uri));
if (_uri != null) {
// result = new Uri[]{_uri};
// TODO: send result;
encodedVideoPath = _uri;
//mUploadMessage.onReceiveValue(new Uri[]{_uri});
mChatWebView.post(new Runnable() {
@Override
public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.videoEncodeEnd('"+_uri+"');");
}
});
}
} catch (Throwable throwable) {
throwable.printStackTrace();
}
......
......@@ -42,7 +42,7 @@ public class VideoEncoder {
private String mInputFile;
@SuppressLint("LongLogTag")
public String changeResolution(File f) throws Throwable {
public String changeResolution(File f, Runnable callBack) throws Throwable {
mInputFile = f.getAbsolutePath();
String filePath = mInputFile.substring(0, mInputFile.lastIndexOf(File.separator));
......@@ -64,7 +64,7 @@ public class VideoEncoder {
}
mOutputFile = outFile.getAbsolutePath();
ChangerWrapper.changeResolutionInSeparatedThread(this);
ChangerWrapper.changeResolutionInSeparatedThread(this, callBack);
return mOutputFile;
}
......@@ -73,22 +73,23 @@ public class VideoEncoder {
private Throwable mThrowable;
private VideoEncoder mChanger;
private ChangerWrapper(VideoEncoder changer) {
private Runnable mCallBack;
private ChangerWrapper(VideoEncoder changer, Runnable callBack) {
mChanger = changer;
mCallBack = callBack;
}
@Override
public void run() {
try {
mChanger.prepareAndChangeResolution();
mChanger.prepareAndChangeResolution(mCallBack);
} catch (Throwable th) {
mThrowable = th;
}
}
public static void changeResolutionInSeparatedThread(VideoEncoder encoder) throws Throwable {
ChangerWrapper wrapper = new ChangerWrapper(encoder);
public static void changeResolutionInSeparatedThread(VideoEncoder encoder, Runnable callBack) throws Throwable {
ChangerWrapper wrapper = new ChangerWrapper(encoder, callBack);
Thread th = new Thread(wrapper, ChangerWrapper.class.getSimpleName());
th.start();
// th.join();
......@@ -98,7 +99,7 @@ public class VideoEncoder {
}
}
private void prepareAndChangeResolution() throws Exception {
private void prepareAndChangeResolution(Runnable callBack) throws Exception {
Exception exception = null;
MediaCodecInfo videoCodecInfo = selectCodec(OUTPUT_VIDEO_MIME_TYPE);
......@@ -275,6 +276,7 @@ public class VideoEncoder {
exception = e;
}
}
callBack.run();
}
if (exception != null) {
throw exception;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment