protected Integer doInBackground(String... paths) { Log.i(Prefs.TAG, "doInBackground started..."); // delete previous log GeneralUtils.deleteFileUtil(workFolder + "/vk.log"); PowerManager powerManager = (PowerManager) _act.getSystemService(Activity.POWER_SERVICE); WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VK_LOCK"); Log.d(Prefs.TAG, "Acquire wake lock"); wakeLock.acquire(); EditText commandText = (EditText) findViewById(R.id.CommandText); String commandStr = commandText.getText().toString(); ///////////// Set Command using code (overriding the UI EditText) ///// // String commandStr = "ffmpeg -y -i /sdcard/DCIM/Camera/in.mp4 -strict experimental -s // 320x240 -r 30 -aspect 3:4 -ab 48000 -ac 2 -ar 22050 -vcodec mpeg4 -b 2097152 // /sdcard/DCIM/Camera/out.mp4"; // String[] complexCommand = {"ffmpeg", "-y" ,"-i", // "/sdcard/DCIM/Camera/in.mp4","-strict","experimental","-s", "160x120","-r","25", "-vcodec", // "mpeg4", "-b", "150k", "-ab","48000", "-ac", "2", "-ar", "22050", // "/sdcard/DCIM/Camera/out.mp4"}; /////////////////////////////////////////////////////////////////////// LoadJNI vk = new LoadJNI(); try { // complex command // vk.run(complexCommand, workFolder, getApplicationContext()); vk.run(GeneralUtils.utilConvertToComplex(commandStr), workFolder, getApplicationContext()); // running without command validation // vk.run(complexCommand, workFolder, getApplicationContext(), false); // copying vk.log (internal native log) to the DCIM/Camera folder GeneralUtils.copyFileToFolder(vkLogPath, demoVideoFolder); // } catch (CommandValidationException e) { // Log.e(Prefs.TAG, "vk run exeption.", e); // commandValidationFailedFlag = true; } catch (Throwable e) { Log.e(Prefs.TAG, "vk run exeption.", e); } finally { if (wakeLock.isHeld()) wakeLock.release(); else { Log.i(Prefs.TAG, "Wake lock is already released, doing nothing"); } } Log.i(Prefs.TAG, "doInBackground finished"); return Integer.valueOf(0); }
@Override protected void onPostExecute(Integer result) { Log.i(Prefs.TAG, "onPostExecute"); progressDialog.dismiss(); super.onPostExecute(result); // finished Toast String rc = null; if (commandValidationFailedFlag) { rc = "Command Vaidation Failed"; } else { rc = GeneralUtils.getReturnCodeFromLog(vkLogPath); } final String status = rc; CompressSimple.this.runOnUiThread( new Runnable() { public void run() { Toast.makeText(CompressSimple.this, status, Toast.LENGTH_LONG).show(); if (status.equals("Transcoding Status: Failed")) { Toast.makeText( CompressSimple.this, "Check: " + vkLogPath + " for more information.", Toast.LENGTH_LONG) .show(); } } }); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.compress_page); demoVideoFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM/Camera/"; demoVideoPath = demoVideoFolder + "in.mp4"; Log.i( Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(getApplicationContext())); workFolder = getApplicationContext().getFilesDir().getAbsolutePath() + "/"; Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder); vkLogPath = workFolder + "vk.log"; Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath); GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(this, workFolder); GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(this, demoVideoFolder); Button invoke = (Button) findViewById(R.id.invokeButton); invoke.setOnClickListener( new OnClickListener() { public void onClick(View v) { Log.i(Prefs.TAG, "run clicked."); if (GeneralUtils.checkIfFileExistAndNotEmpty(demoVideoPath)) { new TranscdingBackground(CompressSimple.this).execute(); } else { Toast.makeText( getApplicationContext(), demoVideoPath + " not found", Toast.LENGTH_LONG) .show(); } } }); int rc = GeneralUtils.isLicenseValid(getApplicationContext(), workFolder); Log.i(Prefs.TAG, "License check RC: " + rc); }