public
class
MyActivity
extends
Activity {
private
static
VideoView mVideoView;
private
static
FfmpegController mFfmpegController;
private
static
Utility mUtility;
private
WebView webView;
String UrlString[] =
new
String[
300
];
String RealUrlString[] =
new
String[
200
];
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
initInstances();
initUi();
}
private
void
initUi() {
setContentView(R.layout.main);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(
true
);
webView.addJavascriptInterface(
new
MyJavaScriptInterface(
this
),
"HtmlViewer"
);
webView.setWebViewClient(
new
WebViewClient() {
@Override
public
void
onPageFinished(WebView view, String url) {
if
(url.contains(
"mapdata"
)) {
webView.setVisibility(View.GONE);
webView.loadUrl(
"javascript:window.HtmlViewer.showHTML"
+
"(document.getElementsByTagName('html')[0].innerHTML);"
);
}
}
});
mVideoView = (VideoView) findViewById(R.id.videoView);
mImageView = (ImageView) findViewById(R.id.imageView);
}
private
void
initInstances() {
mFfmpegController =
new
FfmpegController(
this
);
mUtility =
new
Utility(
this
);
}
class
MyJavaScriptInterface {
private
Context ctx;
MyJavaScriptInterface(Context ctx) {
this
.ctx = ctx;
}
public
void
showHTML(String html)
throws
InterruptedException {
int
i =
0
;
Toast.makeText(getApplicationContext(), html, Toast.LENGTH_LONG).show();
StringTokenizer tmpStr =
new
StringTokenizer(html,
","
);
while
(tmpStr.hasMoreElements()) {
UrlString[i] = (String) tmpStr.nextElement();
i++;
}
i =
0
;
while
(i <
100
) {
RealUrlString[i] = UrlString[
2
* i] + UrlString[
2
* i +
1
];
new
HttpReqTask().execute(RealUrlString[i],
"img0000"
+ i);
i++;
}
Toast.makeText(getApplicationContext(), RealUrlString[
3
], Toast.LENGTH_LONG).show();
}
}
public
void
onClickConvertImg2Video(View view) {
AsyncTask asyncTask =
new
AsyncTask() {
ProgressDialog mProgressDialog;
@Override
protected
void
onPreExecute() {
mProgressDialog =
new
ProgressDialog(MyActivity.
this
);
mProgressDialog.setMessage(
"Converting..."
);
mProgressDialog.setCancelable(
false
);
mProgressDialog.show();
}
@Override
protected
Object doInBackground(Object... params) {
mFfmpegController.convertImageToVideo(mUtility.getPathOfAppInternalStorage() +
"/"
+
"img%05d.jpg"
);
mFfmpegController.convertImageToVideo(getApplicationContext().getFilesDir().getAbsolutePath() +
"/"
+
"img%05d.jpg"
);
return
null
;
}
@Override
protected
void
onPostExecute(Object o) {
Log.e(
"tag"
,
"======================== Video Process Complete ======================================"
);
Log.e(
"Video Path"
,
"Path - "
+ mFfmpegController.pathOuputVideo());
mProgressDialog.dismiss();
}
};
asyncTask.execute();
}
public
void
onClickPlayVideo(View view) {
playVideo();
}
public
void
playVideo() {
mVideoView.setVideoPath(mFfmpegController.pathOuputVideo());
mVideoView.start();
}
private
String saveToInternalStorage(Bitmap bitmapImage) {
ContextWrapper cw =
new
ContextWrapper(getApplicationContext());
File directory = cw.getDir(
"imageDir"
, Context.MODE_PRIVATE);
File mypath =
new
File(directory,
"profile.jpg"
);
FileOutputStream fos =
null
;
try
{
fos =
new
FileOutputStream(mypath);
bitmapImage.compress(Bitmap.CompressFormat.PNG,
100
, fos);
fos.close();
}
catch
(Exception e) {
e.printStackTrace();
}
return
directory.getAbsolutePath();
}
private
void
saveInputImgToAppInternalStorage() {
for
(
int
i =
0
; i <=
10
; i++) {
String imgName = String.format(
"img%05d"
, i);
int
imgResId = getResources().getIdentifier(imgName,
"raw"
, getPackageName());
mUtility.saveFileToAppInternalStorage(getResources().openRawResource(imgResId), imgName +
".bmp"
);
}
}
}