Commit eb84ed53 by Lee Munkyeong

動画エンコード実装

parent d8023f43
...@@ -792,12 +792,12 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity { ...@@ -792,12 +792,12 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
return; return;
} }
/*mChatWebView.post(new Runnable() { mChatWebView.post(new Runnable() {
@Override @Override
public void run() { public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.showLoadingIndicator();"); mChatWebView.loadUrl("javascript:CHAT_UI.showLoadingIndicator();");
} }
});*/ });
if (dataUri != null) { if (dataUri != null) {
Cursor cursor = getContentResolver().query(dataUri, null, null, null, null); Cursor cursor = getContentResolver().query(dataUri, null, null, null, null);
...@@ -807,28 +807,27 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity { ...@@ -807,28 +807,27 @@ public class ChatWebViewActivity extends CommunicationWebViewActivity {
cursor.close(); cursor.close();
Runnable r = new Runnable() { Runnable r = new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
Context c = getApplicationContext(); //CallBack
File file = new File(filePath); Runnable callBack = new Runnable() {
String encodedPath = new VideoEncoder().changeResolution(file);
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 @Override
public void run() { public void run() {
mChatWebView.loadUrl("javascript:CHAT_UI.videoEncodeEnd('"+_uri+"');"); 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, callBack);
encodedFilePath = encodedPath;
} catch (Throwable throwable) { } catch (Throwable throwable) {
throwable.printStackTrace(); throwable.printStackTrace();
} }
......
...@@ -42,7 +42,7 @@ public class VideoEncoder { ...@@ -42,7 +42,7 @@ public class VideoEncoder {
private String mInputFile; private String mInputFile;
@SuppressLint("LongLogTag") @SuppressLint("LongLogTag")
public String changeResolution(File f) throws Throwable { public String changeResolution(File f, Runnable callBack) throws Throwable {
mInputFile = f.getAbsolutePath(); mInputFile = f.getAbsolutePath();
String filePath = mInputFile.substring(0, mInputFile.lastIndexOf(File.separator)); String filePath = mInputFile.substring(0, mInputFile.lastIndexOf(File.separator));
...@@ -64,7 +64,7 @@ public class VideoEncoder { ...@@ -64,7 +64,7 @@ public class VideoEncoder {
} }
mOutputFile = outFile.getAbsolutePath(); mOutputFile = outFile.getAbsolutePath();
ChangerWrapper.changeResolutionInSeparatedThread(this); ChangerWrapper.changeResolutionInSeparatedThread(this, callBack);
return mOutputFile; return mOutputFile;
} }
...@@ -73,22 +73,23 @@ public class VideoEncoder { ...@@ -73,22 +73,23 @@ public class VideoEncoder {
private Throwable mThrowable; private Throwable mThrowable;
private VideoEncoder mChanger; private VideoEncoder mChanger;
private Runnable mCallBack;
private ChangerWrapper(VideoEncoder changer) { private ChangerWrapper(VideoEncoder changer, Runnable callBack) {
mChanger = changer; mChanger = changer;
mCallBack = callBack;
} }
@Override @Override
public void run() { public void run() {
try { try {
mChanger.prepareAndChangeResolution(); mChanger.prepareAndChangeResolution(mCallBack);
} catch (Throwable th) { } catch (Throwable th) {
mThrowable = th; mThrowable = th;
} }
} }
public static void changeResolutionInSeparatedThread(VideoEncoder encoder) throws Throwable { public static void changeResolutionInSeparatedThread(VideoEncoder encoder, Runnable callBack) throws Throwable {
ChangerWrapper wrapper = new ChangerWrapper(encoder); ChangerWrapper wrapper = new ChangerWrapper(encoder, callBack);
Thread th = new Thread(wrapper, ChangerWrapper.class.getSimpleName()); Thread th = new Thread(wrapper, ChangerWrapper.class.getSimpleName());
th.start(); th.start();
// th.join(); // th.join();
...@@ -98,7 +99,7 @@ public class VideoEncoder { ...@@ -98,7 +99,7 @@ public class VideoEncoder {
} }
} }
private void prepareAndChangeResolution() throws Exception { private void prepareAndChangeResolution(Runnable callBack) throws Exception {
Exception exception = null; Exception exception = null;
MediaCodecInfo videoCodecInfo = selectCodec(OUTPUT_VIDEO_MIME_TYPE); MediaCodecInfo videoCodecInfo = selectCodec(OUTPUT_VIDEO_MIME_TYPE);
...@@ -275,6 +276,7 @@ public class VideoEncoder { ...@@ -275,6 +276,7 @@ public class VideoEncoder {
exception = e; exception = e;
} }
} }
callBack.run();
} }
if (exception != null) { if (exception != null) {
throw exception; 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